如何回应这个价值

时间:2014-03-13 17:17:42

标签: php echo

我从XML文件中获取此值

<InfoExtractor:views>35490904</InfoExtractor:views> 

从 - http://www.infoextractor.org/upfiles/songlinks.txt.xml

我使用此代码时没有显示

foreach ($viewfile->channel->item as $viewfileinfo):
        $title=$viewfileinfo->title;
        $views=$viewfileinfo->InfoExtractor:views;

echo "<span> ",$title,"</span> <br/> <span> ",$views,"</span> <br/>";

当我回显时标题显示正常,但是如何将视图值输出到echo?

==========

我找到了答案,我将行改为

$views=$viewfileinfo->children('InfoExtractor', true)->views;

这会考虑冒号。

1 个答案:

答案 0 :(得分:0)

您可以使用get_object_vars捕获数组,然后查看所有键和值以准确确定要回显的内容:

$views_array = get_object_vars($views);

foreach ($views_array as $key => $value) {
    echo 'key = '.$key.', value = '.$value.'<br/>';
}