我需要从以下xml中获取url2
的值:
<videoplayer>
<embed_code>aaa</embed_code>
<volume>bbb</volume>
<stats_pixel>
<secret>ccc</secret>
<url>ddd</url>
<url2>HOW TO GET THIS???</url2>
<video_plays>
<site_url>eee</site_url>
</video_plays>
</stats_pixel>
</videoplayer>
这不起作用:
$xml = simplexml_load_file($url);
$xml->videoplayer[0]->stats_pixel->url2;
答案 0 :(得分:1)
videoplayer
是root,所以你不应该指定它,这应该有效:
echo $xml->stats_pixel->url2;;
答案 1 :(得分:0)
您可能需要对网址进行编码:
$xml = simplexml_load_file(rawurlencode($url));
var_dump($xml); //make sure you get a SimpleXMLElement here before using it...