Reputation: 55
I am trying to get the nodeValue of any tag found in an html page but am getting an error and i can't figure what is causing that error. Fatal error: Fatal error: Call to undefined method DOMDocument::getElementByTagName() in C:\xampplite\htdocs\msite\getscriptnodeValue.php on line 5..here is my code..Can anyone please help me??Thnxx in advance.
$file=file_get_contents('test.txt');
$doc=new DOMDocument();
@$doc->loadHTML('<?xml encoding="UTF-8">'.$file);
$data=$doc->getElementByTagName('div');
for($i=0;$i<$data->length;$i++){
$getTag=$data->item($i);
echo $getTag->nodeValue;
echo"<br/>";
}
Upvotes: 0
Views: 148
Reputation: 64526
The method name is getElementsByTagName()
(with an S) not getElementByTagName()
.
Change to:
$data=$doc->getElementsByTagName('div');
// ^ missing s
Upvotes: 1