PHP读写XML文件
发布日期:2025-05-05 02:03:31 浏览次数:2 分类:精选文章

本文共 935 字,大约阅读时间需要 3 分钟。

formatOutput = true;$rootElement = $dom->createElement("article");$titleElement = $dom->createElement("title", "PHP访问MySql数据库 初级篇");$linkElement = $dom->createElement("link", "http://blog.csdn.net/morewindows/article/details/7102362");$rootElement->appendChild($titleElement);$rootElement->appendChild($linkElement);$dom->appendChild($rootElement);// 保存XML文件$filename = "D:/test.xml";echo $dom->save($filename) . "字节";// 读取XML文件$filename = "D:/test.xml";$dom = new DOMDocument('1.0', 'UTF-8');$dom->load($filename);$articles = $dom->getElementsByTagName("article");echo "文章结点个数: " . $articles->length . "
";foreach ($articles as $article) { $id = $article->getElementsByTagName("id")->item(0)->nodeValue; $title = $article->getElementsByTagName("title")->item(0)->nodeValue; $link = $article->getElementsByTagName("link")->item(0)->nodeValue; $articleArray[$id] = array( "title" => $title, "link" => $link );}var_dump($articleArray);?>
上一篇:PHP读写XML文件
下一篇:PHP请求https域名发生segment fault段错误

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2026年06月05日 00时19分59秒