PHP實(shí)現(xiàn)瀏覽器格式化顯示XML的方法示例
本文實(shí)例講述了PHP實(shí)現(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操作的在線工具供大家參考使用:
在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson
在線格式化XML/在線壓縮XML:
http://tools.jb51.net/code/xmlformat
XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress
XML代碼在線格式化美化工具:
http://tools.jb51.net/code/xmlcodeformat
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP針對(duì)XML文件操作技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
php使用filter_var函數(shù)判斷郵箱,url,ip格式示例
這篇文章主要介紹了php使用filter_var函數(shù)判斷郵箱,url,ip格式,簡(jiǎn)單分析了php filter_var函數(shù)的功能、參數(shù),并結(jié)合實(shí)例形式給出了filter_var函數(shù)判斷郵箱,url,ip格式的相關(guān)操作技巧,需要的朋友可以參考下2019-07-07
php 數(shù)組的指針操作實(shí)現(xiàn)代碼
php 數(shù)組的指針操作實(shí)現(xiàn)代碼,數(shù)組在php編寫中是非常重要的操作,學(xué)習(xí)php的朋友可以參考下。2011-02-02
Thinkphp中的curd應(yīng)用實(shí)用要點(diǎn)
這篇文章主要介紹了Thinkphp中的curd應(yīng)用實(shí)用要點(diǎn)并附上了簡(jiǎn)單的示例,是篇非常不錯(cuò)的文章,這里推薦給大家。2015-01-01
php Redis函數(shù)用法實(shí)例總結(jié)【附php連接redis單例類】
這篇文章主要介紹了php Redis函數(shù)用法,結(jié)合實(shí)例形式總結(jié)分析了php redis操作常用函數(shù)及具體使用方法,并附帶php連接redis單例類,需要的朋友可以參考下2017-11-11
php通過function_exists檢測(cè)函數(shù)是否存在的方法
這篇文章主要介紹了php通過function_exists檢測(cè)函數(shù)是否存在的方法,實(shí)例分析了php使用function_exists檢測(cè)函數(shù)是否存在及調(diào)用的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03
require(),include(),require_once()和include_once()的異同
require(),include(),require_once()和include_once()的異同...2007-01-01
基于preg_match_all采集后數(shù)據(jù)處理的一點(diǎn)心得筆記(編碼轉(zhuǎn)換和正則匹配)
這篇文章主要介紹了采集后數(shù)據(jù)處理的一點(diǎn)心得筆記,編碼轉(zhuǎn)換和正則匹配,基于preg_match_all,需要的朋友可以參考下2014-01-01
PHP的郵件群發(fā)系統(tǒng)phplist配置方法詳細(xì)總結(jié)
這篇文章主要介紹了PHP郵件群發(fā)系統(tǒng)phplist配置方法,結(jié)合實(shí)例形式詳細(xì)總結(jié)分析了PHP郵件群發(fā)系統(tǒng)phplist的配置與使用技巧,需要的朋友可以參考下2016-03-03

