dongzhouhao4316 2011-04-27 08:06
浏览 67

php脚本无法用冒号(:)读取xml数据

I tried to read youtube xml data width php but stuck because youtube uses colon (:)in his API To be precise, here is script I use:

$video = array('/some arrays here,separated width commas/');// array of youtube videos

$v = preg_replace("/[^A-Za-z0-9\-\_]/","",$_GET["v"]); // make sure "v" parameter is sanitized

if(!empty($v) && in_array($v,$video)){ //check if parameter "v" is empty and is yours video
    echo('<object width="853" height="505"><param name="movie" value="http://www.youtube.com/v/'.$v.'&hl=en_US&fs=1&hd=1&color1=0xe1600f&color2=0xfebd01"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'.$v.'&hl=en_US&fs=1&hd=1&color1=0xe1600f&color2=0xfebd01" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="853" height="505"></embed></object>');     
}else{
    foreach($video as $v){
        echo('
        <div class="tube"><a href="/pages/tube.php?v='.$v.'" class="thickbox"><img style="border:2px solid #000;margin:5px;" alt="" src="http://i1.ytimg.com/vi/'.$v.'/default.jpg"/></a>');
        $xmlData = simplexml_load_string(file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$v.'?fields=title,yt:recorded'));//it should be working if I add fields just separated width commas

        $title = (string)$xmlData->title;
        $recorded = (string)$xmlData->recorded;//It should be yt:recorded but I understand that cant use : here!

        {        echo '<p>'.$recorded.' '.$title.'</p></div>';    }
    }
}

It works fine width just title. Is it possible to read somehow yt:recorded

  • 写回答

1条回答

  • dongxie1907 2011-04-27 08:16
    关注

    You need to fetch the namespace first before trying to access it's values. Have a look at the method getNamespaces. Using children you can then access values inside a namespace:

    $namespaces = $entry->getNameSpaces(true);
    $yr = $entry->children($namespaces['yt']); 
    echo $yr->recorded;
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?