phpsimplexml加载远程xml返回bool(false)


php simplexml load remote xml returns bool(false)

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

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

当我运行这个脚本时,它的echo"bool(false)"我做错了什么?谢谢

以下是解决您问题的方法:

$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>