ÈçºÎʹÓÃPHP DOMDocument´´½¨¶¯Ì¬XMLÎļþ
µ±´¦Àí»ùÓÚXMLÓ¦ÓóÌÐòʱ£¬¿ª·¢Õß¾³£ÐèÒª½¨Á¢XML±àÂëÊý¾Ý½á¹¹¡£ÀýÈ磬WebÖлùÓÚÓû§ÊäÈëµÄXML״̬ģ°å£¬·þÎñÆ÷ÇëÇóXMLÓï¾ä£¬ÒÔ¼°»ùÓÚÔËÐÐʱ¼ä²ÎÊýµÄ¿Í»§ÏìÓ¦¡£
¾¡¹ÜXMLÊý¾Ý½á¹¹µÄ¹¹½¨±È½Ï·Ñʱ£¬µ«Èç¹ûʹÓóÉÊìµÄPHP DOMÓ¦ÓóÌÐò½Ó¿Ú£¬Ò»Çж¼»á±äµÃ¼òµ¥Ã÷ÁË¡£±¾ÎĽ«ÏòÄã½éÉÜPHP DOMÓ¦ÓóÌÐò½Ó¿ÚµÄÖ÷Òª¹¦ÄÜ£¬ÑÝʾÈçºÎÉú³ÉÒ»¸öÕýÈ·µÄXMLÍêÕûÎļþ²¢½«Æä±£´æµ½´ÅÅÌÖС£
´´½¨ÎĵµÀàÐÍÉùÃ÷
Ò»°ã¶øÑÔ£¬XMLÉùÃ÷·ÅÔÚÎĵµ¶¥²¿¡£ÔÚPHPÖÐÉùÃ÷Ê®·Ö¼òµ¥£ºÖ»ÐèʵÀý»¯Ò»¸öDOMÎĵµÀàµÄ¶ÔÏ󲢸³ÓèËüÒ»¸ö°æ±¾ºÅ¡£²é¿´³ÌÐòÇåµ¥A£º
³ÌÐòÇåµ¥ A
<?php
// create doctype
$dom = new DOMDocument("1.0");
// display document in browser as plain text
// display document in browser as plain text
// for readability purposes
header("Content-Type: text/plain");
// save and display tree
echo $dom->saveXML();
?>
Çë×¢ÒâDOMÎĵµ¶ÔÏóµÄsaveXML()·½·¨¡£ÉÔºóÎÒÔÙÏêϸ½éÉÜÕâÒ»·½·¨£¬ÏÖÔÚÄãÖ»ÐèÒª¼òµ¥ÈÏʶµ½ËüÓÃÓÚÊä³öXMLÎĵµµÄµ±Ç°¿ìÕÕµ½Ò»¸öÎļþ»òä¯ÀÀÆ÷¡£ÔÚ±¾Àý£¬ÎªÔöÇ¿¿É¶ÁÐÔ£¬ÎÒÒѾ½«ASCIIÂëÎı¾Ö±½ÓÊä³öÖÁä¯ÀÀÆ÷¡£ÔÚʵ¼ÊÓ¦ÓÃÖУ¬¿É½«ÒÔtext/XMLÍ·Îļþ·¢Ë͵½ä¯ÀÀÆ÷¡£
ÈçÔÚä¯ÀÀÆ÷Öв鿴Êä³ö£¬Äã¿É¿´µ½ÈçÏ´úÂ룺
<?xml version="1.0"?>
Ìí¼ÓÔªËØºÍÎı¾½Úµã
XMLÕæÕýÇ¿´óµÄ¹¦ÄÜÊÇÀ´×ÔÆäÔªËØÓë·â×°µÄÄÚÈÝ¡£ÐÒÔ˵ÄÊÇ£¬Ò»µ©Äã³õʼ»¯DOMÎĵµ£¬ºÜ¶à²Ù×÷±äµÃºÜ¼òµ¥¡£´Ë¹ý³Ì°üº¬ÈçÏÂÁ½²½Ö裺
¶ÔÏëÌí¼ÓµÄÃ¿Ò»ÔªËØ»òÎı¾½Úµã£¬Í¨¹ýÔªËØÃû»òÎı¾ÄÚÈݵ÷ÓÃDOMÎĵµ¶ÔÏóµÄcreateElement()»òcreateTextNode()·½·¨¡£Õ⽫´´½¨¶ÔÓ¦ÓÚÔªËØ»òÎı¾½ÚµãµÄжÔÏó¡£
ͨ¹ýµ÷ÓýڵãµÄappendChild()·½·¨£¬²¢°ÑÆä´«µÝ¸øÉÏÒ»²½Öд´½¨µÄ¶ÔÏ󣬲¢ÔÚXMLÎĵµÊ÷Öн«ÔªËØ»òÎı¾½ÚµãÌí¼Óµ½¸¸½Úµã¡£
ÒÔÏ·¶Àý½«Çå³þµØÑÝʾÕâ2²½Ö裬Çë²é¿´³ÌÐòÇåµ¥B¡£
³ÌÐòÇåµ¥ B
<?php
// create doctype
$dom = new DOMDocument("1.0");
// display document in browser as plain text
// for readability purposes
header("Content-Type: text/plain");
// create root element
$root = $dom->createElement("toppings");
$dom->appendChild($root);
// create child element
$item = $dom->createElement("item");
$root->appendChild($item);
// create text node
$text = $dom->createTextNode("pepperoni");
$
Ïà¹ØÎĵµ£º
PHPÁ÷³Ì¿ØÖÆ
ÔÚÈκÎÒ»ÃųÌÐòÉè¼ÆÓïÑÔÖУ¬¶¼ÐèÒªÖ§³ÖÂú×ã³ÌÐò½á¹¹»¯ËùÐèÒªµÄÈýÖÖ»ù±¾½á¹¹
˳Ðò½á¹¹
·ÖÖ§½á¹¹£¨Ñ¡Ôñ½á¹¹£©
Ñ»·½á¹¹
ÔÚPHPÖУ¬ÎªÖ§³ÖÕâÈýÖֽṹ£¬ÌṩÁËʵÏÖÕâÈýÖֽṹËùÐèµÄÓï¾ä¡£
1¡¢Ë³Ðò½á¹¹£º
ÔÚ³ÌÐò½á¹¹ÖУ¬×î»ù±¾µÄ¾ÍÊÇ˳Ðò½á¹¹¡£³ÌÐò»á°´ÕÕ×ÔÉ϶øÏµÄ˳ÐòÖ´ÐдúÂ룬»ù±¾ÐÎʽΪ£º
Óï¾ä1;
Óï ......
PHP±äÁ¿µÄ±äÁ¿£¬¼´¿É±ä±äÁ¿
¿É±ä±äÁ¿µÄ¸ÅÄͨ¹ý»ñȡһ¸ö±äÁ¿µÄÖµ×öΪÁíÍâÒ»¸ö±äÁ¿µÄÃû³ÆÀ´²Ù×÷±äÁ¿£¬¾ÍÊÇ¿ÉÒÔ±äÁ¿¡£
¡¾Ê¾Àý¡¿
Îı¾²é¿´¸´ÖÆ´úÂë´òÓ¡¹ØÓÚ
<?php
$a = 'hello'; //ÆÕͨ±äÁ¿
$$a = ' ......
PHP³£Á¿
³£Á¿Êǹ̶¨µÄÊýÖµÀýÈçÔ²ÖÜÂÊ£¬ÓÃÒ»¸ö¼òµ¥µÄ±êʶ·û½øÐж¨Ò壨Ãû×Ö£©¡£³£Á¿Ä¬ÈÏΪ´óСдÃô¸Ð¡£°´ÕÕ¹ßÀý³£Á¿±êʶ·û×ÜÊÇ´óдµÄ¡£
³£Á¿ÃûºÍÆäËüÈκΠPHP ±êÇ©×ñÑͬÑùµÄÃüÃû¹æÔò¡£ºÏ·¨µÄ³£Á¿ÃûÒÔ×Öĸ»òÏ»®Ïß¿ªÊ¼£¬ºóÃæ¸ú×ÅÈκÎ×Öĸ£¬Êý×Ö»òÏ»®Ïß¡£
³£Á¿µÄ¶¨Ò壺¿ÉÒÔÓà define( ) º¯ÊýÀ´¶¨Òå³£Á¿¡£Ò»¸ö³£Á¿Ò»µ©±»¶¨Ò ......
<?php
/*
* Created on 2009-10-23
* ·Ö×ÓÈçÃÎo(╯¡õ╰)o
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class people
{
private $name;
pu ......