Search the Community
Showing results for tags 'meta tags'.
-
Folks, I found this piece of code on my notes. Cannot remember where I grabbed it from. It is supposed to fetch a page and grab it's meta details and display them on screen. Question is: What is this error I am getting ? Fatal error: Uncaught TypeError: DOMDocument::loadHTML() expects parameter 1 to be string, boolean given in C:\xampp\htdocs\curl\filter.php:31 Stack trace: #0 C:\xampp\htdocs\curl\filter.php(31): DOMDocument->loadHTML(false) #1 {main} thrown in C:\xampp\htdocs\curl\filter.php on line 31 <?php /* ERROR HANDLING */ declare(strict_types=1); ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $data = curl_exec($ch); curl_close($ch); return $data; } $html = file_get_contents_curl("https://www.google.com/search?q=dirty+harry&oq=dirty+harry&aqs=chrome..69i57.2604j0j7&sourceid=chrome&ie=UTF-8"); //parsing begins here: $doc = new DOMDocument(); @$doc->loadHTML($html); $nodes = $doc->getElementsByTagName('title'); //get and display what you need: $title = $nodes->item(0)->nodeValue; $metas = $doc->getElementsByTagName('meta'); for ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); if($meta->getAttribute('name') == 'description') $description = $meta->getAttribute('content'); if($meta->getAttribute('name') == 'keywords') $keywords = $meta->getAttribute('content'); } echo "Title: $title". '<br/><br/>'; echo "Description: $description". '<br/><br/>'; echo "Keywords: $keywords"; ?> <br> This is line 31 in my NotePad++: @$doc->loadHTML($html);
- 7 replies
-
- meta tags
- meta keywords
-
(and 3 more)
Tagged with:
-
I am using html5 and all the pages have h2 headings as titles. They all show up in google search results fine. The only thing that doesn't show up fine are some of the descriptions under each heading. Some meta descriptions show up fine under the correct heading title, while rest shows ALL the heading tags AS description under each search result. For eg. Cars www.mywebsite.com/category?id=5&name=cars 4 days ago - Mywebsite · Login · Signup · About · Lola's Dress · Create a product · Find Products · News Feed. Recent Products ... The above description includes the h2 heading tags of all the pages when it should only show the description of the page that I setup in the meta tags. Anyone know why this is happening?