Recently I have been experimenting with making my own rudimentary search engine. Things have been going smoothly as I have the URL's and URL hashes logged into my phpMyAdmin database, no title or descriptions were logged but the program did work with sites such as YouTube, Google, and a local music venue. However recently I have encountered an error that I can't seem to fix and is stopping new websites from being added to my table and I have been receiving this error message:
Notice: Trying to get property 'nodeValue' of non-object in C:\xampp\htdocs\se\index.php on line 22
I have tried making slight adjustments, such as ensuring that the item is an object by using a code
if (is_object($title ->item(0))) {
$title = $title->item(0)->nodeValue;
}
// Does not work, PHP Recoverable fatal error: Object of class DOMNodeList could not be converted
// to string...
but this only lead to an issue that would not allow the program to move forward.
here is the preceding code up until the error
$already_crawled = array();
$crawling = array();
function get_details($url) {
$options = array('http' => array('method' => "GET", 'headers' => "User-Agent: howBot/0.1\n"));
$context = stream_context_create($options);
$doc = new DOMDocument();
@$doc->loadHTML(@file_get_contents($url, false, $context));
$title = $doc->getElementsByTagName("title");
$title = $title->item(0)->nodeValue; // error occurs here
I am using php7 and I'm still relatively new to it so any other advice would help. Thanks