我无法使用 simplexml 在 php 中解析名称中包含“-”的标签。
这是 xml- http://synd.cricbuzz.com/score-gadget/gadget-scores-feed.xml
无法解析 url-text 和 url-link。出现以下错误 - 1) 使用未定义的常量文本 - 在 C:\wamp\www\score1.php 中假设为“文本” 2) 使用未定义的常量链接 - 假设为' C:\wamp\www\score1.php 中的链接' 3)2) 使用未定义的常量链接-假定 C:\wamp\www\score1.php 中的 'url' 请帮助我 php 将 url-text 解析为单独变量——“url”和“text”
这是代码
<?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);
?>