Getting title and meta tags from external website
This is the way it should be:
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("http://example.com/");//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";
<?php// Assuming the above tags are at www.example.com$tags = get_meta_tags('http://www.example.com/');// Notice how the keys are all lowercase now, and// how . was replaced by _ in the key.echo $tags['author']; // nameecho $tags['keywords']; // php documentationecho $tags['description']; // a php manualecho $tags['geo_position']; // 49.33;-86.59?>