Home > Backend Development > PHP Tutorial > php解析xml字符串,该怎么处理

php解析xml字符串,该怎么处理

WBOY
Release: 2016-06-13 13:27:35
Original
729 people have browsed it

php解析xml字符串
我有这样1个字符串
$xmlStr ="1Test01402Test02
80
";

想得到以下的内容
Id = 1
Name = Test01
Point = 40

Id = 2
Name = Test02
Point = 80
怎么才能够实现

------解决方案--------------------

PHP code
$xml=simplexml_load_string($xmlStr);

foreach($xml->Body->Content as $item) {
  foreach($item as $k=>$v)
    echo "$k $v\n";
}
<br><font color="#e78608">------解决方案--------------------</font><br>使用该贴的相关程序,可以很省事,避免的换行等标识符的干扰:<br>http://topic.csdn.net/u/20120229/17/2d8adf3f-5273-4330-a399-b67b5e395e3d.html<br>这个帖子的#17内容及关联内容。<br>具体就是:<br>1、将数组编译为xml字符串 dump_xml_config();<br>2、将xml字符串写入文件 file_put_contents_safe();<br>3、http://topic.csdn.net/u/20120228/09/cf787cd0-5936-4a15-9661-895f362b5b16.html<br>#10,将xml文件内容转换为数组 parse_xml_config()。<br>取你要用的就可以了。 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
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