php simplexml 加载远程 xml 返回 bool(false) [英] php simplexml load remote xml returns bool(false)
本文介绍了php simplexml 加载远程 xml 返回 bool(false)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写这个 php 脚本是为了解析一些 XML 文档.
I write this php script in order to parse some XML doc.
$xml = simplexml_load_file('http://www1.cbs.gov.il/xml/indices_heb_all.xml');
var_dump($xml);
当我运行这个脚本时,它的 echo "bool(false)"我做错了什么?谢谢!
When I run this script its echo "bool(false)" What I'm doing wrong? Thanks!
推荐答案
以下是解决您问题的方法:
Here is what would solve your problem:
$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 才能正确显示文本:
But the encoding has to be set to UTF-8 for the text to be displayed correctly:
<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>
这篇关于php simplexml 加载远程 xml 返回 bool(false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文