如何解析名称中包含' - '的xml标签?
问题描述:
我不能在php中用simplexml解析名称中包含“ - ”的标签。如何解析名称中包含' - '的xml标签?
这是XML的 http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml
accoured-未定义的常量文本的 1)使用URL,文字和网址链接无法parsed.following错误 - 在C假定“文本”:\ WAMP \ www \ score1.php 2)使用未定义的常量链接 - 在C:\ wamp \ www \ score1.php中假定为'link'3)2)使用未定义的常量链接 - 在C:\ wamp中假定'url' \ www \ score1.php plz help me php正在解析url-text作为分隔变量 - “url”和“text”
这是t他的代码
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache"); Header('Pragma: no-cache');
$url = "http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml";
//$url = "C:\wamp\www\score.xml";
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec ($curl);
curl_close ($curl);
print $result;
$fp = fopen('score.xml', 'w');
if($fp)
fwrite($fp, $result);
else
echo "Error !";
$url = "score.xml";
$xml = simplexml_load_file($url,null, LIBXML_NOCDATA);
foreach ($xml->match as $xmlinfo):
$header=$xmlinfo->header;
$description=$xmlinfo->description;
$urltext=$xmlinfo->url-text;
$urllink=$xmlinfo->url-link;
echo $header,$description,$urltext;
endforeach;
//var_dump($xml);
?>
答
访问包含PHP下的命名约定不 允许的字符在XML文档中的元素(如连字符)可以是 ,通过将元素名称封装在大括号和 撇号中来实现。
你的情况:
$xmlinfo->{'url-text'}