php xml 格式化,PHP实现浏览器格式化显示XML的方法示例
本文實(shí)例講述了PHP實(shí)現(xiàn)瀏覽器格式化顯示XML的方法。分享給大家供大家參考,具體如下:
在頭部加上
header("Content-type: application/xml");
剛開(kāi)始加上了發(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操作的在線工具供大家參考使用:
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
總結(jié)
以上是生活随笔為你收集整理的php xml 格式化,PHP实现浏览器格式化显示XML的方法示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 用Java统计姓氏个数_JAVA统计数字
- 下一篇: php人民币转换,PHP字符串转换RMB