4
I have a code that should take the title of the page example "Facebook - sign in or register" only that is giving error in this line
$title = $dom->getElementsByTagName('title')->item('0')->nodeValue;
that is the code:
function website_title($urli) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $urli); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // define um usuário agente. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36'); $html = curl_exec($ch); curl_close($ch); $dom = new DOMDocument; @$dom->loadHTML($html); $title = $dom->getElementsByTagName('title')->item('0')->nodeValue; return $title; } echo website_title('https://www.facebook.com/');
if anyone can help me I’m grateful.
Makes a
print_r( $dom->getElementsByTagName('title'));
puts the result there.– rray
OK, here I go to test
– Gabriel José
appeared these errors: <pre>Notice: Trying to get Property of non-object in ... line 143</pre> <pre>Notice: Undefined variable: dom in .......... line 143</pre> <pre>Fatal error: Call to a Member Function getelementsbytagname() on null in ........... line 148 </pre>
– Gabriel José