php simplexml load remote xml返回bool(false)

时间:2014-10-29 16:05:29

标签: php xml xml-parsing simplexml

我编写这个php脚本是为了解析一些XML文档。

$xml = simplexml_load_file('http://www1.cbs.gov.il/xml/indices_heb_all.xml');
var_dump($xml);

当我运行此脚本时,它的回显“bool(false)” 我做错了什么? 谢谢!

1 个答案:

答案 0 :(得分:0)

以下是解决问题的方法:

$xml = simplexml_load_string(str_replace('iso-8859-8-i', 'iso-8859-8', file_get_contents('http://www1.cbs.gov.il/xml/indices_heb_all.xml')));
var_dump($xml);

但必须将编码设置为UTF-8才能正确显示文本:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<?php
$xml = simplexml_load_string(str_replace('iso-8859-8-i', 'iso-8859-8', file_get_contents('http://www1.cbs.gov.il/xml/indices_heb_all.xml')));
var_dump($xml);
?>
</body>
</html>