Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

php½âÎöxmlʾÀý

<!-- xml ¸ñʽ
<books>
<book id='1001'>
<author>andylin</author>
<title>c language</title>
<publisher id="aaa">O'Reilly</publisher>
</book>

<book id='1002'>
<author>congfeng</author>
<title>C++ Designer</title>
<publisher id='bbb'>New Publish</publisher>
</book>
</books>
-->
<?php
$dom = new DOMDocument();
if (!$dom->load('books.xml'))
{
echo "load books.xml failed!<br>";
return;
}

$books = $dom->getElementsByTagName('book');
foreach ($books as $book)
{
//get book id
$book_id = $book->getAttribute('id');

//get author
$nodeAuth = $book->getElementsByTagName('author');
$strAuth = $nodeAuth->item(0)->nodeValue;
//get publisher
$nodePub = $book->getElementsByTagName('publisher');
$strPub = $nodePub->item(0)->nodeValue;
$pub_id = $nodePub->item(0)->getAttribute('id');
//get title
$nodeTitle = $book->getElementsByTagName('title');
$strTitle = $nodeTitle->item(0)->nodeValue;

//save data
$arrInfo['book_id'] = $book_id;
$arrInfo['author'] = $strAuth;
$arrInfo['publiser'] = $strPub;
$arrInfo['title'] = $strTitle;
$arrInfo['pub_id'] = $pub_id;
//save info
$arrInfos[] = $arrInfo;
}

var_dump($arrInfos);
?>

 


Ïà¹ØÎĵµ£º

PHP Êý×éºÍ×Ö·û´®»¥Ïàת»»

PHP ÖÐÓÉÓÚÊý×éºÍ×Ö·û´®ÕâÁ½ÖÖ±äÁ¿ÀàÐÍÊÇÈç´Ë³£Óã¬ÒÔÖÁÓÚ PHP ¾ßÓÐÁ½¸öº¯Êý£¬¿ÉÒÔÔÚ×Ö·û´®ºÍÊý×éÖ®¼ä»¥Ïà½øÐÐת»»¡£
¡¡¡¡$array=explode(separator,$string);
¡¡¡¡$string=implode(glue,$array);
¡¡¡¡Ê¹ÓúÍÀí½âÕâÁ½¸öº¯ÊýµÄ¹Ø¼üÖ®´¦ÊÇ·Ö¸ô·û£¨separator£©ºÍ½ººÏ·û£¨glue£©¹Øϵ¡£µ±°ÑÒ»¸öÊý×éת»»³ÉÒ»¸ö×Ö·û´®Ê±£¬½«»áÉ ......

Óà PHP ¶ÁÈ¡ºÍ±àд XML DOM


Óà PHP ¶ÁÈ¡ºÍ±àд XML DOM
ʹÓà DOM ¿â¡¢SAX ½âÎöÆ÷ºÍÕýÔò±í´ïʽ
ÎĵµÑ¡Ïî
´òÓ¡±¾Ò³
½«´ËÒ³×÷Ϊµç×ÓÓʼþ·¢ËÍ
¼¶±ð£º Öм¶
Jack Herrington (jack_d_herrington@codegeneration.net), ¸ß¼¶Èí¼þ¹¤³Ìʦ, "Code Generation Network"
2006 Äê 2 ÔÂ 06 ÈÕ
ÓÐÐí¶à¼¼Êõ¿ÉÓÃÓÚÓà PHP ¶ÁÈ¡ºÍ±àд XML¡£±¾ÎÄÌṩÁËÈýÖÖ ......

ʹÓà PHP ´¦Àí XML ÅäÖÃÎļþ


ʹÓà PHP ´¦Àí XML ÅäÖÃÎļþ
ʹÓà XML ÅäÖÃÎļþÇáÒ×µØÅäÖà PHP Ó¦ÓóÌÐòºÍ¶ÔÏó
¼¶±ð£º Öм¶
Vikram Vaswani, ´´Ê¼ÈË, Melonfire
2007 Äê 11 ÔÂ 29 ÈÕ
XML ΪӦÓóÌÐòÅäÖÃÎļþÌṩÁËÒ»ÖÖ±ã½Ý¡¢Ò×Óõıí´ïÓïÑÔ¡£µ«ÓÐʱºò½«ÕâЩÐÅÏ¢ÌáÈ¡µ½ PHP ½Å±¾Öн«»áÃæ¶ÔÒ»¸ö²»Ð¡µÄÌôÕ½¡£ÕâÕýÊÇ XJConf for PHP °ü³öÏÖµÄÔ­Òò£ºËüÌá ......

PHPʵÀý£ºÓÃPHP¼òµ¥ÊµÏÖ¶àÌõ¼þ²éѯ

ÔÚÎÒÃǵÄÍøÕ¾Éè¼Æ¹ý³ÌÖУ¬¾­³£»áÓõ½¶àÌõ¼þ²éѯ£¬±¾ÎĵÄÔ´ÂëÊÇÒ»¸ö¶þÊÖ·¿ÎݲéѯµÄÀý×Ó¡£ÔÚ±¾ÀýÖУ¬ÎÒÃÇҪʵÏÖÄܹ»Í¨¹ýµØÀíλÖã¬ÎïÒµÀàÐÍ£¬·¿Îݼ۸ñ£¬·¿ÎÝÃæ»ý¼°ÐÅÏ¢·¢²¼ÈÕÆڵȶà¸öÌõ¼þ²éѯµ½¿Í»§ËùÐèµÄ×ÊÁÏ¡£
²éѯÎļþ£¨search.php£©
Ò»¡¢Éú³É²éѯÓï¾ä£º
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
<?
$conn=mysql_connect("localhost", ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ