$count = 11;
for ($i=11;$i>0;$i--)
{
$url = "http://bet.hkjc.com/racing/getXML.aspx?type=win&RaceNo=".$i;
//$url = "http://www.astarsagent.com/race/getXML.xml";
print_r($url."<br/>");
$array = array();
if (($response_xml_data = file_get_contents($url))===false)
{
echo "Error fetching XML<br/>";
} else
{
libxml_use_internal_errors(true);
$data = simplexml_load_string($response_xml_data);
if (!$data)
{
echo "Error loading XML<br/>";
foreach(libxml_get_errors() as $error)
{
echo "\t", $error->message;
print_r("<br/><br/><br/>------------------------------------------------------------------------<br/><br/><br/>");
retry;
}
} else
{
$array = xml2array($data);
printpre($array[WIN]);
if(count($array[WIN]))
{
break;
}else
{
print_r("N".$i."<br/><br/><br/>");
$count--;
}
}
}
}//End for
print_r("raceNum:".$count);
我想在xml包含数据时计算一个数字。解析很成功。
有时我会得到
[Error loading XML Start tag expected, '<' not found]
at the line
[echo "Error loading XML<br/>";]
那里有什么问题?
XML:
<?xml version='1.0'?>
<ROOT>
<WIN DATE="26-04-2017" VENUE="HV" updateDate="26-04-2017" updateTime="19:15:54">
<RACE NUM="1" TIME="191554" FINAL_COLLATE="1" ID="25328" PID="25420">
<OUT TYPE="O" NUM="1" WILLPAY="2650" HF="1" BIG_DROP="0" ODDSDROP="7.14">2.6</OUT>
<OUT TYPE="O" NUM="2" WILLPAY="6550" HF="3" BIG_DROP="0" ODDSDROP="0.00">6.5</OUT>
<OUT TYPE="O" NUM="3" WILLPAY="19550" HF="0" BIG_DROP="0" ODDSDROP="0.00">19</OUT>
<OUT TYPE="O" NUM="4" WILLPAY="12700" HF="0" BIG_DROP="0" ODDSDROP="0.00">12</OUT>
<OUT TYPE="O" NUM="5" WILLPAY="3550" HF="2" BIG_DROP="0" ODDSDROP="7.89">3.5</OUT>
<OUT TYPE="O" NUM="6" WILLPAY="134000" HF="0" BIG_DROP="0" ODDSDROP="0.00">134</OUT>
<OUT TYPE="O" NUM="7" WILLPAY="11450" HF="0" BIG_DROP="0" ODDSDROP="35.29">11</OUT>
<OUT TYPE="O" NUM="8" WILLPAY="19650" HF="0" BIG_DROP="0" ODDSDROP="29.63">19</OUT>
<OUT TYPE="O" NUM="9" WILLPAY="18000" HF="0" BIG_DROP="0" ODDSDROP="0.00">18</OUT>
<OUT TYPE="O" NUM="10" WILLPAY="36800" HF="0" BIG_DROP="0" ODDSDROP="0.00">36</OUT>
<OUT TYPE="O" NUM="11" WILLPAY="30800" HF="0" BIG_DROP="0" ODDSDROP="0.00">30</OUT>
<OUT TYPE="O" NUM="12" WILLPAY="75700" HF="0" BIG_DROP="0" ODDSDROP="0.00">75</OUT>
</RACE>
</WIN>
</ROOT>