How to resolve xml into an array

Source: Internet
Author: User
Xml is parsed into an array. the xml file format is XMLcode & lt ;? Xmlversion & quot; 1.0 & quot; encoding & quot; UTF-8 & quot ;? & Gt; & lt; note & gt; & lt; title & gt; Baidu Online Translation & lt; title & gt; & lt; body & gt; baidu translation is a free online translation service that parses Chinese and English xml into an array.
My xml file format is:
XML code
  
  
  
   Baidu online translationBaidu translation is a free online translation service that supports text and webpage translation between Chinese and English, Chinese and Japanese. you only need to enter the text or webpage address you want to translate, you can easily get the translation results.
   <Em> English </em> _ Baidu Encyclopedia
   EnglishEnglish is one of the working languages of the United Nations and is also a de facto language for international communication.
   EnglishIt belongs to the Spanish branch of the Japanese family in the Indian and European languages, and is spread...
   Hujiang <em> English </em> Network-the most affinity original <em> English </em> Learning website, <em> English </em> learner's ideal...Hujiang District
   EnglishIs the most user-friendly original in China
   EnglishLearning websites are also leading
   EnglishLearning Portal websites with the most popular free online
   EnglishLearn the test system and focus on creating the most popular
   EnglishThe interactive learning platform is...
  




How to parse an array
PHP code
  Array ('title' => 'Baidu online translation', 'body' => 'Baidu translation is a free online translation service, supports text and webpage translation between Chinese and English, Chinese and Japanese. you only need to enter the text or webpage address you want to translate to get the translation result easily. '), Array ('title' =>'English_ Baidu Encyclopedia ', 'body' =>'EnglishEnglish is one of the working languages of the United Nations and is also a de facto language for international communication.EnglishIt belongs to the Spanish branch of the Japanese family in the Indian and European languages and is spread to... 'through British colonial activities ...'))


------ Solution --------------------
PHP code
$s=file_get_contents('bb.xml');preg_replace('/(.*)<\/title>\s*(.*)<\/body>/e','$ar[]=array(\'title\'=>"$1",\'body\'=>"$2")',$s);print_r($ar); 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.