Home  >  Article  >  php教程  >  解决PHP SimpleXML 不支持命名空间的问题

解决PHP SimpleXML 不支持命名空间的问题

WBOY
WBOYOriginal
2016-06-13 09:33:16775browse

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

  芒果小站

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

  $content = "

  芒果小站

  //替换字符串

  $content = str_replace('xxx:', '', $content);

  //读取替换后的字符串

  $xml = simplexml_load_string($content);

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

Statement:
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