这篇文章主要介绍了php+xml编程之SimpleXML的应用,实例分析了SimpleXML函数操作XML文件的方法,需要的朋友可以参考下
本文实例讲述了php+xml编程之SimpleXML的应用。分享给大家供大家参考。具体如下:
SimpleXML的核心思想:以面向对象的方式来操作xml文件,它会将xml文件的所有元素都转成对象。
xml文档:words.xml
复制代码 代码如下:
simplexml使用实例:
复制代码 代码如下:
echo "
";<br> $words = simplexml_load_file("words.xml");//返回数组对象,,可以用print_r()或var_dump()查看<br> var_dump($words);<br> ?> <p>读取内容:<br> </p><p><span>复制代码</span> 代码如下:</p><p> echo "</p><pre class="brush:php;toolbar:false">";<br> $words = simplexml_load_file("words.xml");//返回数组对象,可以用print_r()或var_dump()查看<br> //echo $words->word[2];<br> foreach($words->word as $row){//$row还是一个对象<br> print_r($row);<br> echo $row->ch."<hr>"; //其实,$row->ch还是一个对象,只不能它能echo出来<br> }<br> ?><br> 第二段代码输出结果:<br> <p><span>复制代码</span> 代码如下:</p><p>SimpleXMLElement Object<br> (<br> [en] => boy<br> [ch] => 男孩<br> )<br> 男孩<br> SimpleXMLElement Object<br> (<br> [en] => girl<br> [ch] => 女孩<br> )<br> 女孩<br> SimpleXMLElement Object<br> (<br> [en] => teacher<br> [ch] => 老师<br> )<br> 老师</p> <p>希望本文所述对大家的php+xml程序设计有所帮助。</p>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools
