Home >Backend Development >PHP Tutorial >PHP提取XML有关问题

PHP提取XML有关问题

WBOY
WBOYOriginal
2016-06-13 10:15:47796browse

PHP提取XML问题

XML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?xml version="1.0" encoding="utf-8"?><user>        <person_siteurl>http://www.163.com</person_siteurl>        <job_keys>PHP</job_keys>        <job_keys>JAVA</job_keys>        <job_keys>PYTHON</job_keys>        <email>[email protected]</email></user>

以上是XML,怎么将里面的数据提取出来,结果如下:
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$arr = array(   'person_siteurl'=>'http://www.163.com',   'job_keys'=>'php,java,python',    'email'=>[email protected]')



谢谢~~

------解决方案--------------------
PHP code
$arr=(array)simplexml_load_file('user.xml');$res=array_map(function($param){return is_array($param)?implode(',',$param):$param;},$arr);print_r($res);<div class="clear">
                 
              
              
        
            </div>
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