Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP解析XML链接_Php_Html_Xml_Parsing_Xml Parsing - Fatal编程技术网

用PHP解析XML链接

用PHP解析XML链接,php,html,xml,parsing,xml-parsing,Php,Html,Xml,Parsing,Xml Parsing,我有一个XML提要,看起来像这样: <link href="http://www.picturebox.tv/watchnow?id=UKIC30" rel="alternate"/> 我可以使用simpleXML轻松解析标题: $pictureBoxXMLFeed = simplexml_load_file('https://www.picturebox.tv/xml/feeds/FindAnyFilm/FindAnyFilm.xml');; echo $pictureBox

我有一个XML提要,看起来像这样:

<link href="http://www.picturebox.tv/watchnow?id=UKIC30" rel="alternate"/>

我可以使用simpleXML轻松解析标题:

$pictureBoxXMLFeed = simplexml_load_file('https://www.picturebox.tv/xml/feeds/FindAnyFilm/FindAnyFilm.xml');;

echo $pictureBoxXMLFeed->entry[1]->title;

foreach($pictureBoxXMLFeed->entry as $value){

    echo $value->title;
    echo '<br/>';

}
$pictureboxmlfeed=simplexml\u load\u文件('https://www.picturebox.tv/xml/feeds/FindAnyFilm/FindAnyFilm.xml');;
echo$PictureBoxMLFeed->条目[1]->标题;
foreach($PictureBoxMLFeed->输入为$value){
echo$value->title;
回声“
”; }
但是我需要抓取提要中的link元素,它看起来像这样:

<link href="http://www.picturebox.tv/watchnow?id=UKIC30" rel="alternate"/>

仅供参考,这不起作用:

echo$value->link

感谢您的帮助……

试试这个:

$pictureBoxXMLFeed = simplexml_load_file('https://www.picturebox.tv/xml/feeds/FindAnyFilm/FindAnyFilm.xml',LIBXML_NOEMPTYTAG);

然后查看链接是否通过

在每个$value中,它都是一个simplexml_元素,href是一个属性,因此需要检查

foreach ($value->attributes as $a) {
  if ($a->getName() == "href") { do something; }
}
$value->{“href”}
这个怎么样

$pictureBoxXMLFeed = simplexml_load_file('https://www.picturebox.tv/xml/feeds/FindAnyFilm/FindAnyFilm.xml');;

foreach($pictureBoxXMLFeed->entry[1] as $value){
    if($value->getName() == 'link') {
    echo $value->asXML();
    }
}
这就是你的意思吗

$string = '
<entry>
    <link href="http://www.picturebox.tv/watchnow?id=UKIC30" rel="alternate"/>
</entry>';

$simpleXML = simplexml_load_string($string);
foreach($simpleXML->link->attributes() as $name => $value) {
    echo $name.': '.$value.'<br />';
}

href是一个属性,因此:

foreach($pictureBoxXMLFeed->entry as $value){
    echo $value->link['href'];
    echo '<br/>';
}
foreach($pictureboxmlfeed->entry as$value){
echo$value->link['href'];
回声“
”; }

foreach($pictureboxmlfeed->entry as$value){
echo$value->link->attributes()->href;
回声“
”; }
Define“not work”-它只是没有显示任何内容还是抛出了错误?没有显示任何内容,它会像DreamWeaver中的echo那样突出显示,让我相信它是保留的?如果XML的根元素是entry,那么就不需要解决它。echo$pictureBoxXMLFeed->link->attributes()->href<代码>$value->link
工作正常。但是元素是空的,那么输出应该是什么呢?如果您在使用href属性,那么查看一下就会知道您需要使用
$value->link['href']可能重复的文件被加载到简单的XML中。他试图通过不正确的访问检索属性。
foreach($pictureBoxXMLFeed->entry as $value){
    echo $value->link->attributes()->href;
    echo '<br/>';
}