由于换行而导致的SimpleXML Parse错误

时间:2014-03-10 11:42:05

标签: php xml parsing rss

这是导致问题的xml的一部分。

<jobUrlParameter>?jobid=59077373</jobUrlParameter><jobClientRef
erence>

当我尝试使用simplexml_load_file加载文件时,xml中的随机元素会发生这种情况会导致以下解析错误。

Warning: simplexml_load_file(): parser error : expected '>' 

我是新手,所以我有什么方法可以删除元素之间的换行符吗?

1 个答案:

答案 0 :(得分:0)

将文件加载到字符串中,通过str_replace()运行字符串并使用simplexml_load_string()

这样的东西
$xml=file_get_contents('path/to/file.xml');
$xml=str_replace("\n",'',$xml);
$simple=simplexml_load_string($xml);
相关问题