Horje Website
Extract title description keyword php – Meta Tag

Here is example of code to Get title description keyword image php

 
 
  1. <?php
  2. // Web page URL
  3. $url = 'https://www.codexworld.com/';
  4. // Extract HTML using curl
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_HEADER, 0);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($ch, CURLOPT_URL, $url);
  9. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  10. $data = curl_exec($ch);
  11. curl_close($ch);
  12. // Load HTML to DOM object
  13. $dom = new DOMDocument();
  14. @$dom->loadHTML($data);
  15. // Parse DOM to get Title data
  16. $nodes = $dom->getElementsByTagName('title');
  17. $title = $nodes->item(0)->nodeValue;
  18. // Parse DOM to get meta data
  19. $metas = $dom->getElementsByTagName('meta');
  20. $description = $keywords = '';
  21. for($i=0; $i<$metas->length; $i++){
  22. $meta = $metas->item($i);
  23. if($meta->getAttribute('name') == 'description'){
  24. $description = $meta->getAttribute('content');
  25. }
  26. if($meta->getAttribute('name') == 'keywords'){
  27. $keywords = $meta->getAttribute('content');
  28. }
  29. }
  30. echo "Title: $title". '<br/>';
  31. echo "Description: $description". '<br/>';
  32. echo "Keywords: $keywords";
  33. ?>
Published:
November 23, 2022
Author:
admin
Category:
Full Tutorials
Views:
16

This article was posted in Full Tutorials. Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Horje © 2011 - 2022