0

I wrote the following code to get the title of a webpage. But the code doesn't work and output this error message: Object of class DOMElement could not be converted to string

$html = file_get_contents("http://mysmallwebpage.com/");
$dom = new DOMDocument;
@$dom->loadHTML($html);

$links = $dom->getElementsByTagName('title');

foreach ($links as $title)
{               
    echo (string)$title."<br>";
}

Could you please show me with an example?

Justin k
  • 1,104
  • 5
  • 22
  • 33

0 Answers0