本文实例讲述了php+xml编程之SimpleXML的应用。分享给大家供大家参考。具体如下:
SimpleXML的核心思想:以面向对象的方式来操作xml文件,它会将xml文件的所有元素都转成对象。
xml文档:words.xml
代码如下:
boy
男孩
girl
女孩
teacher
老师
beauty
美女
simplexml使用实例:
代码如下:
echo "
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ";<br>
$words = simplexml_load_file( "words.xml" );
var_dump( $words );<br>
?>
<p>读取内容:<br>
</p><p class = "codetitle" > 代码如下:</p><p class = "codebody" id= "code50691" >
echo "</p><pre class=" brush:php;toolbar:false ">" ;<br>
$words = simplexml_load_file( "words.xml" );
foreach ( $words ->word as $row ){
print_r( $row );<br>
echo $row ->ch. "<hr>" ;
}<br>
?><br>
第二段代码输出结果:<br>
<p class = "codetitle" > 代码如下:</p><p class = "codebody" id= "code90212" >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>
|
Nach dem Login kopieren