Home  >  Article  >  Backend Development  >  xml解析成一个数组,该怎么处理

xml解析成一个数组,该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:33:48949browse

xml解析成一个数组
我的xml文件格式是:

XML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?xml version="1.0" encoding="utf-8"?><note><title>百度在线翻译</title>百度翻译是一项免费的在线翻译服务,支持中文和英文、中文和日文之间的文本、网页翻译功能,只需输入您想要翻译的文本或者网页地址,即可轻松获得翻译结果。<title>
<em>英语</em>_百度百科</title>
<em>英语</em>(English)是联合国的工作语言之一,也是事实上的国际交流语言。<em>英语</em>属于印欧语系中日耳曼语族下的西日耳曼语支,并通过英国的殖民活动传播到...     <title>沪江<em>英语</em>网—最具亲和力的原创<em>英语</em>学习网站,<em>英语</em>学习者的理想...</title>沪江<em>英语</em>是国内最具亲和力的原创<em>英语</em>学习网站,也是领先的<em>英语</em>学习门户网站,拥有最受欢迎的免费在线<em>英语</em>学习测试系统,专注于打造最具人气的<em>英语</em>学习交流互动平台,为...</note>




怎样解析成一个数组
PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->array(array('title'=>'百度在线翻译','body'=>'百度翻译是一项免费的在线翻译服务,支持中文和英文、中文和日文之间的文本、网页翻译功能,只需输入您想要翻译的文本或者网页地址,即可轻松获得翻译结果。'),array('title'=>'<em>英语</em>_百度百科','body'=>'<em>英语</em>(English)是联合国的工作语言之一,也是事实上的国际交流语言。<em>英语</em>属于印欧语系中日耳曼语族下的西日耳曼语支,并通过英国的殖民活动传播到...     '))


------解决方案--------------------
PHP code
$s=file_get_contents('bb.xml');preg_replace('/<title>(.*)\s*</title>(.*)/e','$ar[]=array(\'title\'=>"$1",\'body\'=>"$2")',$s);print_r($ar);<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