Home > Backend Development > PHP Tutorial > php怎么解析xml标签里面的内容?

php怎么解析xml标签里面的内容?

WBOY
Release: 2016-06-20 12:43:03
Original
1072 people have browsed it


 
    Weekly(%1s)


想保留Weekly(%1s)

谢谢


回复讨论(解决方案)

没人么?正确方法可以加分

前面的name是固定的吗?

xliff XML本地化数据交换格式,在 android 文本资源文件中使用
php 并不支持 android 应用开发,所以也没有提供相关的解析支持
你可以变通一下

$s =<<< XML<?xml version="1.0" encoding="utf-8"?><resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">     <string name="repeat_item_week">Weekly(<xliff:g id="MONTH">%1s</xliff:g>)</string></resources>XML;$x = simplexml_load_string($s);echo strip_tags($x->string->asXML(), '<xliff:g>');
Copy after login
Weekly(<xliff:g id="MONTH">%1s</xliff:g>)
Copy after login

使用simpleXML_load_file 或 simpleXML_load_string即可。
会解释为数组的。

有关键字部分需要使用cdata包含

$xml =<<     XML;$data = simpleXML_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);  echo '';echo $data->string;echo '';
Copy after login

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template