Php xml data parsing code _ PHP Tutorial

Source: Internet
Author: User
PHPXML data parsing code. The code for copying the code is as follows: xmlstring $ xml_string? Xmlversion1.0? UsersusernameFoonameemailfoo@bar.comnameuserusernameFoobarnameemailfoobar @ foo. The code is as follows:


// Xml string
$ Xml_string ="


Foo
Foo@bar.com


Foobar
Foobar@foo.com

";

// Load the xml string using simplexml
$ Xml = simplexml_load_string ($ xml_string );

// Loop through the each node of user
Foreach ($ xml-> user as $ user)
{
// Access attribute
Echo $ user ['id'], '';
// Subnodes are accessed by-> operator
Echo $ user-> name ,'';
Echo $ user-> email ,'
';
}


This is an excerpt from an article published before the home of scripts. For more tips, refer.
Collected 21 practical and convenient PHP function code

The http://www.bkjia.com/PHPjc/321852.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321852.htmlTechArticle code is as follows: // xml string $ xml_string = "? Xml version = '1. 0 '? Users user id = '20140901' nameFoo/name emailfoo@bar.com/name/user id = '20160901' nameFoobar/name emailfoobar @ foo ....

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.