½â¶ÁPHP DOMDocumentÔÚ½âÎöXMLÎļþÖеÄ×÷ÓÃ
½â¶ÁPHP DOMDocumentÔÚ½âÎöXMLÎļþÖеÄ×÷ÓÃ
http://developer.51cto.com 2009-12-02 10:39 ØýÃû Áø³Ç²©¿Í ÎÒÒªÆÀÂÛ(0)
PHP DOMDocumentµÄ¹¦Äܷdz£Ç¿´ó£¬ÎÒÃÇÔÚÕâƪÎÄÕÂÖн«½éÉÜÈçºÎÕýÈ·µÄÔËÓÃPHP DOMDocumentÀ´½øÐÐXMLÎļþµÄ½âÎö¡£Ï£Íû¶ÔÓÖÐèÒªµÄÅóÓÑÓÐËù°ïÖú¡£
ÔÚʹÓÃPHP¶ÔXMLÎļþ½øÐнâÎöµÄʱºò£¬ÎÒÃÇ¿ÉÒÔÓúܶ෽·¨¡£ÔÚÕâÀÎÒÃǽ«Îª´ó¼ÒÖصã½éÉÜÈçºÎʹÓÃPHP DOMDocumentÀ´¼°ÄæÐÐÄܹ»XMLÎļþµÄ½âÎö¡£
¹ØÓÚÓõ½µÄXMLÎļþ»¹ÒÔ“Php Xml´¦ÀíÖ®simplexmlʹÓ÷½·¨Ç³Ì¸”Ò»ÎÄÖеÄXMLΪÀý£¬ÎļþÃûΪ£ºme.xml¡£´úÂëÈçÏ£º
PHP XML´¦ÀíXML´úÂë
<?xml version="1.0" encoding="utf-8"?>
<phplamp>
<post>
<title id="1">PHP XML´¦Àí½éÉÜÒ»</title>
<details>ÏêϸÄÚÈÝÒ»</details>
</post>
<post>
<title id="2">PHP XML´¦Àí½éÉܶþ</title>
<details>ÏêϸÄÚÈݶþ</details>
</post>
<post>
<title id="3">PHP XML´¦Àí½éÉÜÈý</title>
<details>ÏêϸÄÚÈÝÈý</details>
</post>
</phplamp>
È»ºó¾ÍÐèÒªÓÃPHP DOMDocumentÈ¥´¦ÀíÕâ¸öÎļþ£¬½«XMLÎļþÖеÄÈκÎÔªËض¼½âÎö³öÀ´¡£´úÂëÈçÏ£¬ÀïÃæÓÐ×¢ÊÍ¡£
PHP DOMDocument½âÎöXMLÎļþµÄ´úÂë
<?php
// Ê×ÏÈÒª½¨Ò»¸öDOMDocument¶ÔÏó
$xml = new DOMDocument();
// ¼ÓÔØXmlÎļþ
$xml->load("me.xml");
// »ñÈ¡ËùÓеÄpost±êÇ©
$postDom = $xml->getElementsByTagName("post");
// Ñ»·±éÀúpost±êÇ©
foreach($postDom as $post){
// »ñÈ¡Title±êÇ©Node
$title = $post->getElementsByTagName("title");
/**
* Òª»ñÈ¡Title±êÇ©µÄIdÊôÐÔÒª·ÖÁ½²¿×ß
* 1. »ñÈ¡titleÖÐËùÓÐÊôÐÔµÄ
ÁбíÒ²¾ÍÊÇ$title->item(0)->attributes
* 2. »ñÈ¡titleÖÐidµÄÊôÐÔ£¬
ÒòΪÆäÔÚµÚһλËùÒÔÓÃitem(0)
*
* СÌáʾ£º
* ÈôÈ¡ÊôÐÔµÄÖµ¿ÉÒÔÓÃitem(*)->nodeValue
* ÈôÈ¡ÊôÐԵıêÇ©¿ÉÒÔÓÃitem(*)->nodeN
Ïà¹ØÎĵµ£º
<?
//
½¨Á¢Ò»¸öÖ¸ÏòÐÂCOM×é¼þµÄË÷Òý
$word
=
new
COM(”word
.
application”) or
die
(”Can
'
t start Word!”);
// ÏÔʾĿǰÕýÔÚʹÓõÄWordµÄ°æ±¾ºÅ
//echo “Loading Word, v. {$word->Version}<br>”;
// °ÑËüµÄ¿É¼ûÐÔÉèÖÃΪ0£¨¼Ù£©£¬Èç¹ûÒ ......
ÔÚwindowsÏ°²×°image magic µÄphpÀ©Õ¹ imagick, Ê×ÏÈÐèÒªÏÂÔØphp_imagick.dllÎļþ.Õâ¸ödllÎļþ·Ç³£¹Ø¼ü.
Èç¹ûÏÂÔØÁË´íÎóµÄphp_imagick.dll.°²×°¾Í»áʧ°Ü.ÎÒ¾ÍÊÇÏÂÔØÁËN¸öÕâÑùµÄdllÎļþ¶¼Î´ÄÜ°²×°³É¹¦.×îºóÖÕÓÚ¸øÎÒÕÒµ½ÕýÈ·µÄdllÎļþÁË
ÏÂÔصØÖ·:http://valokuva.org/outside-blog-content/imagick-windows-builds ......
Óà PHP ¶ÁÈ¡ºÍ±àд XML DOM
ʹÓà DOM ¿â¡¢SAX ½âÎöÆ÷ºÍÕýÔò±í´ïʽ
ÎĵµÑ¡Ïî
´òÓ¡±¾Ò³
½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ
¼¶±ð£º Öм¶
Jack Herrington (jack_d_herrington@codegeneration.net), ¸ß¼¶Èí¼þ¹¤³Ìʦ, "Code Generation Network"
2006 Äê 2 ÔÂ 06 ÈÕ
ÓÐÐí¶à¼¼Êõ¿ÉÓÃÓÚÓà PHP ¶ÁÈ¡ºÍ±àд XML¡£±¾ÎÄÌṩÁËÈýÖÖ ......
PHPÖ§³Ö8ÖÖÔʼÀàÐÍ£¬ÆäÖаüÀ¨£º
4ÖÖ±êÁ¿ÀàÐÍ£ºboolean(²¼¶ûÐÍ)¡¢integer(ÕûÐÍ)¡¢float(¸¡µãÐÍ)¡¢string(×Ö·ûÐÍ)£»
2ÖÖ¸´ºÏÀàÐÍ£ºarray(Êý×é)¡¢object(¶ÔÏó)£»
2ÖÖÌØÊâÀàÐÍ£ºresource(×ÊÔ´)¡¢NULL
Äú¿ÉÄÜ»¹»á¶Áµ½Ò»Ð©¹ØÓÚ“Ë«¾«¶È£¨double£©”ÀàÐ͵IJο¼¡£Êµ¼ÊÉÏ double ºÍ float ÊÇÏàͬµÄ£¬ÓÉÓÚһЩÀúÊ·µÄÔ ......