Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MetaTagParser
- {
- public $metadata;
- private $html;
- private $url;
- public function __construct($url)
- {
- $this->url=$url;
- $this->html= $this->file_get_contents_curl();
- $this->set_title();
- $this->set_meta_properties();
- }
- public function file_get_contents_curl()
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $this->url);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- $data = curl_exec($ch);
- curl_close($ch);
- return $data;
- }
- public function set_title()
- {
- $doc = new DOMDocument();
- @$doc->loadHTML($this->html);
- $nodes = $doc->getElementsByTagName('title');
- $this->metadata['title'] = $nodes->item(0)->nodeValue;
- }
Add Comment
Please, Sign In to add comment