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);