Home > Backend Development > PHP Tutorial > An explanation of the simple implementation method of reading and outputting XML file data with PHP

An explanation of the simple implementation method of reading and outputting XML file data with PHP

jacklove
Release: 2023-04-02 13:16:02
Original
2226 people have browsed it

This article mainly introduces the simple implementation method of PHP reading and outputting XML file data, involving PHP's loading, traversing, reading, output and other related operating skills for xml format file data. Friends in need can refer to the following

The example in this article describes a simple implementation method for PHP to read and output XML file data. Share it with everyone for your reference, the details are as follows:

config.XML file:

<?xml version="1.0" encoding="UTF-8"?>
<node>
  <student>
    <name>张明</name>
    <email>1234567890@qq.com</email>
    <username>一样菜</username>
    <code>985931</code>
  </student>
  <student>
    <name>王红</name>
    <email>2345678901@qq.com</email>
    <username>冰封</username>
    <code>5625362</code>
  </student>
</node>
Copy after login

php file:

<?php
  $file = &#39;config/config.xml&#39;;
  $xml_array=simplexml_load_file($file); //将XML中的数据,读取到数组对象中
  foreach($xml_array as $tmp){
    echo $tmp->name.": ".$tmp->email.", ".$tmp->username.", ".$tmp->code."<br>";
  }
?>
Copy after login

Result

张明: 1234567890@qq.com, 一样菜, 985931
王红: 2345678901@qq.com, 冰封, 5625362
Copy after login

PS: Here are a few more xml operations for you The online tool is for your reference:

OnlineXML/JSON mutual conversion tool:
http ://tools.jb51.net/code/xmljson

Online formattingXML/Online compressionXML
http://tools.jb51.net/code/xmlformat

XMLOnline compression/formatting tool:
http://tools.jb51.net/code/xml_format_compress

XMLCode online formatting Beautification tools:
http://tools.jb51.net/code/xmlcodeformat

##Articles you may be interested in:

thinkphp5 Explanation of how to load static resource paths and constants

A brief analysis of closures and anonymous functions in PHP

Source code analysis Laravel explains the reasons for repeatedly executing the same queue task

The above is the detailed content of An explanation of the simple implementation method of reading and outputting XML file data with PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template