Guest User

Untitled

a guest
Jan 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. class MetaTagParser
  2. {
  3. public $metadata;
  4. private $html;
  5. private $url;
  6.  
  7.  
  8.  
  9.  
  10. public function __construct($url)
  11. {
  12. $this->url=$url;
  13.  
  14. $this->html= $this->file_get_contents_curl();
  15.  
  16. $this->set_title();
  17. $this->set_meta_properties();
  18. }
  19.  
  20. public function file_get_contents_curl()
  21. {
  22. $ch = curl_init();
  23.  
  24. curl_setopt($ch, CURLOPT_HEADER, 0);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  26. curl_setopt($ch, CURLOPT_URL, $this->url);
  27. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  28.  
  29. $data = curl_exec($ch);
  30. curl_close($ch);
  31.  
  32. return $data;
  33. }
  34.  
  35. public function set_title()
  36. {
  37. $doc = new DOMDocument();
  38. @$doc->loadHTML($this->html);
  39. $nodes = $doc->getElementsByTagName('title');
  40.  
  41. $this->metadata['title'] = $nodes->item(0)->nodeValue;
  42. }
Add Comment
Please, Sign In to add comment