Home > php教程 > php手册 > 解决 PHP SimpleXML 不支持命名空间

解决 PHP SimpleXML 不支持命名空间

WBOY
Release: 2016-06-13 11:40:39
Original
954 people have browsed it

很遗憾 PHP SimpleXML 原生不支持解析带命名空间的 XML 数据。比如有份酱紫的 xml 数据:


芒果小站
不知道如何处理,于是恶心了一把:

$content = "
芒果小站
>";
//替换字符串
$content = str_replace('xxx:', '', $content);
//读取替换后的字符串
$xml = simplexml_load_string($content);

直接通过字符串替换把所有的命名空间过滤掉。瞬间搞定,哈哈!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template