I'm using some regexes to parse wiki-styled text.
<?php
function wikiParser($data){
$data = preg_replace('/\[\[Youtube:([a-zA-Z0-9_]+)\]\]/', getYoutubeTitle("$1"), $data);
return $data;
}
?>
This function searches for strings like [[Youtube:b32hRITAAew]] and calles another function getYoutubeTitle(b32hRITAAew).
<?php
function getYoutubeTitle($hash){
$url = 'http://gdata.youtube.com/feeds/api/videos?v=2&q='.$hash.'&max-results=1&fields=entry(title)&prettyprint=true';
$fp = fopen($url, 'r');
$page = '';
while(!feof($fp)){
$page .= fgets($fp, 4096);
}
$titre = eregi("<title>(.*)</title>", $page, $regs);
return $regs[1];
}
?>
The second function parses the response data. In the case of b32hRITAAew code, the following url is accessed
It outputs:
<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns='http://www.w3.org/2005/Atom'>
<entry>
<title>The Lord of the Rings Symphony (1) HQ</title>
</entry>
</feed>
And the title should be The Lord of the Rings Symphony (1) HQ. But for the unknown reason it shows me some random Photography Trick - Easy Image Stabilizer For Any Camera. I've worked hard to solve the issue, but still can't get it how that comes up.
Is there any problem with getYoutubeTitle("$1")
or anything else?