17c02-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 29 行

PHP
29
字号
<?php// Using SimpleXML, read the file into memory:$xml = simplexml_load_file('17c00-1.xml');//$xml = simplexml_load_file('contacts.xml');// Xpath search to find all 'meta' tags no matter what the depth:$meta = $xml->xpath('//meta');// Loop over them and output their IDsforeach ($meta as $m) {    echo "Meta - {$m['id']}<br />\n";}// Find all email tags within a contact tag from the root of the XML document:$email = $xml->xpath('/contacts/contact/email');// Loop over them and output the email addreses:foreach ($email as $e) {    echo "Email - {$e}<br />\n";}// Finally, find any contact who has a cellphone number$cell = $xml->xpath('contact/phone[@type="cell"]/..');// Loop over them and output their names:foreach ($cell as $c) {    echo "Cell Contact - {$c->name}<br />\n";}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?