日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

php xml 格式化,PHP实现浏览器格式化显示XML的方法示例

發(fā)布時間:2025/3/15 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php xml 格式化,PHP实现浏览器格式化显示XML的方法示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文實例講述了PHP實現(xiàn)瀏覽器格式化顯示XML的方法。分享給大家供大家參考,具體如下:

在頭部加上

header("Content-type: application/xml");

剛開始加上了發(fā)現(xiàn)還是不行。最近一直嘗試最后終于找到解決辦法。在代碼最后加上exit;就可以了

$Dom = new \DOMDocument('1.0', 'utf-8');

$paper = $Dom->createElement('paper');

$Dom->appendChild($paper);

$exercises = $Dom->createElement('exercises');

$exercises->setAttribute('id','1');

$exercises->setAttribute('type','1');

$exercises->setAttribute('answer','1');

$paper->appendChild($exercises);

$title = $Dom->createElement('title');

$title->setAttribute('label','1');

$title->setAttribute('mapsrc','1');

$title->setAttribute('soundsrc','1');

$exercises->appendChild($title);

$option = $Dom->createElement('option');

$option->setAttribute('id','1');

$option->setAttribute('label','1');

$option->setAttribute('mapsrc','1');

$option->setAttribute('soundsrc','1');

$exercises->appendChild($option);

header("Content-type: application/xml");

echo $Dom->saveXml(); exit;

終于顯示了,很爽

PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:

希望本文所述對大家PHP程序設(shè)計有所幫助。

總結(jié)

以上是生活随笔為你收集整理的php xml 格式化,PHP实现浏览器格式化显示XML的方法示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。