PHP read and output XML file data Simple implementation method explained

Source: Internet
Author: User
Tags ming
This article mainly introduces the PHP read and output XML file data simple implementation method, involving PHP for XML format file data loading, traversal, reading, output and other related operations skills, the need for friends can refer to the next

In this paper, a simple implementation method of PHP reading and outputting XML file data is described. Share to everyone for your reference, as follows:

Config. XML file:

<?xml version= "1.0" encoding= "UTF-8"?><node>  <student>    <name> Zhang Ming </name>    <email>1234567890@qq.com</email>    <username> Same dishes </username>    <code> 985931</code>  </student>  <student>    <name> Hong Hong </name>    <email> 2345678901@qq.com</email>    <username> ice </username>    <code>5625362</code>  </student></node>

PHP Files:

<?php  $file = ' config/config.xml ';  $xml _array=simplexml_load_file ($file); Reads the data from the XML into the array object in the  foreach ($xml _array as $tmp) {    echo $tmp->name. ":". $tmp->email. ",". $tmp Username. ",". $tmp->code. " <br> ";  }? >

Results

Zhang Ming: 1234567890@qq.com, same dish, 985931 Wang Hong: 2345678901@qq.com, Frozen, 5625362

PS: Here are a few more online tools for you to refer to using XML operations:

Online XML/json Mutual Conversion Tool:
Http://tools.jb51.net/code/xmljson

Online formatting of XML/Online compressed XML:
Http://tools.jb51.net/code/xmlformat

XML Online Compression/formatting tools:
Http://tools.jb51.net/code/xml_format_compress

XML Code online format Beautification tool:
Http://tools.jb51.net/code/xmlcodeformat

Articles you may be interested in:

THINKPHP5 How to load static resource paths and constants

A brief analysis of the closure and anonymous function interpretation in PHP

Source Analysis Laravel The reason for repeating the same queue task

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.