PHPXML data parsing code, json, parser function

Source: Internet
Author: User
Tags xml parser
? Phpxmlstring $ xml_stringquot ;? Xmlversion #39; 1.0 #39; nbsp...
   
   
  
   
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 ,'
';} Json data parsing code: $ json_string =' {"id": 1, "name": "foo", "email": "foo@foobar.com", "interest ": ["wordpress", "php"]} '; $ obj = json_decode ($ json_string); echo $ obj-> name; // prints foo echo $ obj-> interest [1]; // prints php // 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 ,'
';}?>

Php also comes with a php xml Parser

Introduction to php xml Parser

XML functions allow us to parse XML documents, but cannot verify them. XML is a data format used for standard Structured document exchange.

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.