Ask a question about converting xml to php array

Source: Internet
Author: User
Ask a question about xml to php array. I want to receive xml content now, not the file content received by the file in the following format? & Lt ;? Xml & nbsp; version = "1.0" & nbsp; encoding = "UTF-8 "? & Gt; & lt; pReq> & lt; ax & gt; 0000 & lt;/ax & gt; & lt; at & gt: a question about converting xml to php arrays
I want to receive xml content, not a file
The content of the received file is in the following format:

? 0000Ax12711122233344212345Test402100002885328320130828 Note 1 Note 2 Note 3


How can I directly convert this code into a php array? this is not a file but a variable

Share xml php: 0000
------ Solution --------------------
Find a function named xml_to_array, such

Http://www.cnblogs.com/heiing/archive/2009/12/31/1637015.html

Then use it


Function xml_to_array ($ xml)
{
$ Reg = "/<(\ w +) [^>] *?> ([\ X00-\ xFF] *?) <\/\ 1> /";
If (preg_match_all ($ reg, $ xml, $ matches ))
{
$ Count = count ($ matches [0]);
$ Arr = array ();
For ($ I = 0; $ I <$ count; $ I ++)
{
$ Key = $ matches [1] [$ I];
$ Val = xml_to_array ($ matches [2] [$ I]); // recursion
If (array_key_exists ($ key, $ arr ))
{
If (is_array ($ arr [$ key])
{
If (! Array_key_exists (0, $ arr [$ key])
{
$ Arr [$ key] = array ($ arr [$ key]);

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.