English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Simple Implementation Method for Reading and Outputting XML File Data in PHP

This example explains a simple implementation method for PHP to read and output XML file data. Shared for everyone's reference, as follows:

config.XML file:

<?xml version="1.0" encoding="UTF-8"?>
<node>
  <student>
    <name>张明</name>
    <email>[email protected]</email>
    <username>一样菜</username>
    <code>985931</code>
  </student>
  <student>
    <name>王红</name>
    <email>[email protected]</email>
    <username>冰封</username>
    <code>5625362</code>
  </student>
</node>

php file:

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

Result

Zhang Ming: [email protected], 一样菜, 985931
Wang Hong: [email protected], 冰封, 5625362

PS: Here are several online tools for XML operations for your reference and use:

OnlineXML/JSON Conversion Tool:
http://tools.jb51.net/code/xmljson

Online FormattingXML/Online Compression XML:
http://tools.jb51.net/code/xmlformat

XMLOnline Compression/Formatting Tool:
http://tools.jb51.net/code/xml_format_compress

XMLOnline Code Formatting and Beautifying Tool:
http://tools.jb51.net/code/xmlcodeformat

Readers who are interested in more about PHP-related content can check the special topics of this site: 《Summary of PHP Skills for XML File Operation》、《Comprehensive PHP Array (Array) Operation Skills》、《Summary of PHP String (string) Usage》、《Summary of PHP Error and Exception Handling Methods》、《PHP Basic Syntax Tutorial》、《PHP Object-Oriented Program Design Tutorial》and《php+Introduction to MySQL Database Operation Tutorial》and《Summary of Common PHP Database Operation Skills》

I hope this article will be helpful to everyone in PHP program design.

Declaration: The content of this article is from the network, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to notice#w3Please report any violations by email to codebox.com (replace # with @), and provide relevant evidence. Once verified, the website will immediately delete the suspected infringing content.

You May Also Like