Rumah >pembangunan bahagian belakang >tutorial php > php 解析 xml 格式-该怎么处理
php 解析 xml 格式-----急!!!!!!!!!!!!!!
<timezone><br /> <id>hell</id><br /> <raw_offset>2</raw_offset><br /> <dst><br /> <start_month>02</start_month><br /> <start_day>29</start_day><br /> <start_day_of_week>00</start_day_of_week><br /> <start_time_hour>02</start_time_hour><br /> <start_time_minute>00</start_time_minute><br /> <end_month>09</end_month><br /> <end_day>06</end_day><br /> <end_day_of_week>00</end_day_of_week><br /> <end_time_hour>02</end_time_hour><br /> <end_time_minute>00</end_time_minute><br /> </dst><br /> </timezone>
private function writeOrgin(){<br /> //将数组输出到XML文件中<br /> // by MoreWindows( http://blog.csdn.net/MoreWindows )<br /> $article_array = array(<br /> "第一篇" => array(<br /> "title"=>"PHP访问MySql数据库 初级篇",<br /> "link"=>"http://blog.csdn.net/morewindows/article/details/7102362"<br /> ),<br /> "第二篇" => array(<br /> "title"=>"PHP访问MySql数据库 中级篇 Smarty技术",<br /> "link"=>"http://blog.csdn.net/morewindows/article/details/7094642"<br /> ),<br /> "第三篇" => array(<br /> "title"=>"PHP访问MySql数据库 高级篇 AJAX技术",<br /> "link"=>"http://blog.csdn.net/morewindows/article/details/7086524"<br /> ),<br /> );<br /> $dom = new DOMDocument('1.0', 'UTF-8');<br /> $dom->formatOutput = true;<br /> $rootelement = $dom->createElement("MoreWindows");<br /> foreach ($article_array as $key=>$value)<br /> {<br /> $article = $dom->createElement("article", $key);<br /> $title = $dom->createElement("title", $value['title']);<br /> $link = $dom->createElement("link", $value['link']);<br /> $article->appendChild($title);<br /> $article->appendChild($link);<br /> $rootelement->appendChild($article);<br /> }<br /> $dom->appendChild($rootelement);<br /> $filename = "D:\\test.xml";<br /> echo 'XML文件大小' . $dom->save($filename) . '字节';<br /> <br /> }*/<br /> // 不使用<br /> /*<br /> private function readOrgin(){<br /> $filename = "D:\\test.xml";<br /> $article_array = array();<br /> <br /> $dom = new DOMDocument('1.0', 'UTF-8');<br /> $dom->load($filename);<br /> <br /> //得到<article>结点<br /> $articles = $dom->getElementsByTagName("article");<br /> echo '<article> 结点个数 ' . $articles->length;<br /> foreach ($articles as $article)<br /> {<br /> $id = $article->getElementsByTagName("id")->item(0)->nodeValue;<br /> $title = $article->getElementsByTagName("title")->item(0)->nodeValue;<br /> $link = $article->getElementsByTagName("link")->item(0)->nodeValue;<br /> $article_array[$id] = array('title'=>$title, 'link'=>$link);<br /> }<br /> <br /> //输出结果<br /> echo "<pre class="brush:php;toolbar:false">";<br /> var_dump($article_array);<br /> echo "";