This the video from witch i want to get the og:title
http://www.youtube.com/watch?feature=player_embedded&v=A683kmvRH_8
Php code
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($pageurl);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$titleBackUp = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++){
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'title')
$title = $meta->getAttribute('content');
}
The title is Мастило – В ръцете ти е най-добре [HQ] and i’m getting
ÐаÑÑило – Ð ÑÑÑеÑе Ñи е най-добÑе [HQ]
I try also with
curl_setopt( $ch, CURLOPT_ENCODING, "UTF-8" );
but it dosent work.
I try with html_entity_decode but is not working
This can happen if the document itself doesn’t contain a
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />tag.You can try either of the following:
Let
DomDocumentload the HTML directly from the server (i.e. use->loadHTMLFile())Prefix the document with aforementioned meta tag before running it through
->loadHTML().For example, you could do this:
It’s a hack to let libxml know it’s supposed to read utf-8 data … it’s not possible to pass that encoding via
->loadHTML().