[英]Error with simplexml_load_file via HTTP
我在php中使用simplexml_load_file通過HTTP檢索XML內容。
這是我的代碼:
if ($xml = simplexml_load_file($url)) {
$item_list = $xml->xpath("/probabile_formazione/titolari/calciatore");
foreach ($item_list as $item) {
echo $item . ' ';
}
}
如果我使用$ url =“ http://www.gazzetta.it/ssi/2011/boxes/calcio/squadre/cagliari/formazione/formazione.xml ”; 它可以工作,但是如果我使用$ url =“ http://www.gazzetta.it/ssi/2011/boxes/calcio/squadre/atalanta/formazione/formazione.xml ”; 我有這個錯誤:
[2014年9月4日16:37:01] [錯誤] [客戶端127.0.0.1] PHP警告:simplexml_load_file(): http ://www.gazzetta.it/ssi/2011/boxes/calcio/squadre/atalanta/formazione /formazione.xml:1 :解析器錯誤:預期起始標簽,在第42行[var / www / fanta / prova1.php中找不到'<'[2014年9月4日,星期四] [錯誤] [客戶端127.0 .0.1] PHP警告:42行/var/www/fanta/prova1.php中\\ x1f \\ x8b \\ b在第42行上的[x1f \\ x8b \\ b] [2014年9月4日16:37:01] [錯誤] [客戶端127.0.0.1] PHP警告:simplexml_load_file():第42行的/var/www/fanta/prova1.php中的^
你可以幫幫我嗎? 謝謝pasquy73
我認為響應xml格式錯誤。 您應該處理獲取正確xml的可能錯誤,例如:
<?
$url = "http://www.gazzetta.it/ssi/2011/boxes/calcio/squadre/atalanta/formazione/formazione.xml";
libxml_use_internal_errors(true);
if ($xml = simplexml_load_file($url)) {
$item_list = $xml->xpath("/probabile_formazione/titolari/calciatore");
foreach ($item_list as $item) {
echo $item . ' ';
}
}
else {
foreach (libxml_get_errors() as $error) {
print_r($error);
}
libxml_clear_errors();
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.