Ask a question about XML to PHP arrays

Source: Internet
Author: User
Ask a question about XML to PHP array
I'm now going to receive an XML content, not a file
The contents of the received file are formatted as follows

? 0000ax000011122233344212345 Test 402100002885328320130828 notes 1 remark 2 Note 3


How to directly convert this code to PHP array, this is not a file, is a variable

XML PHP

Share to:


------Solution--------------------
Find a Xml_to_array function, like

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]); Recursive
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.