我有这段代码,但我不确定我是否让它工作:
/**
* Function: youtube data grabber
*
* @description :
* @param $ : video code, url type (embed/url)
* @return : data array
* @author : Mamun.
* @last -modified-by: Mamun.
*/
if (! function_exists('youtube_data_grabber'))
{
function youtube_data_grabber($video_code, $link_type = "embed")
{
if ($video_code != '')
{
if ($link_type == "embed")
{
$splited_data = explode("=",$video_code);
$video_unique_code = substr(strrchr($splited_data[4],"/"),1,-strlen(strrchr($splited_data[4],"&")));
}
else if ($link_type == "url")
{
$splited_data = explode("=",$video_code);
$video_unique_code = substr($splited_data[1],0,-strlen(strrchr($splited_data[1],"&")));
}
else
{
return;
}
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'.$video_unique_code;
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
return $sxml;
}
}
} // End Youtube Function
我不确定如何激活它是我想说的。我把它放在 Controller 中,它在我的一个页面的函数中。我没有任何语法错误。我只是不知道如何唤醒它并让它工作。我想我可以只放 youtube_data_grabber('http://www.youtube.com/watch?v=LAcrFym10ZI', 'url');
但那没有用。
我从 this blog 得到代码,并且我有 zend 功能。我之前测试过,没有错误。我只是遇到了这个 youtube 部分的问题。
有什么想法吗?
最佳答案
该代码应该放在助手或插件中,而不是在 Controller 中。该页面上代码的第一部分应该在您的 Controller 中。您粘贴的那个只是一个替代版本。
关于php - 我如何在 CodeIgniter Controller 中调用这个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2933021/