<?xml version= "1.0" encoding= "UTF-8"?><root> <news id= "1" year= "> <title> Haikou Mission Hills Huayi Feng Xiaogang Movie Commune Nanyang Street Grand Open Street </title> <thumbnail>/news/2015/news-12-23_2.jpg</thumbnail> <images> <image> <source>/news/2015/news-12-23.jpg</source> </image> <image> <source>/news/2015/news-12-23_2.jpg</source> </image> <image> <source>/news/2015/news-12-23_3.jpg</source> </image> <image> <source>/news/2015/news-12-23_1.jpg</source> </image> <image> <source>/news/2015/news-12-23_4.jpg</source> </image> </images> </news> <news id= "2" year= > <title> Halloween Raiders: Go deep into Mission hills and become a "ghost expert" </ Title> <thumbnail>/news/2015/1.png</thumbnail> <images> <image> <source>/ news/2015/1.1.jpg</source> </image> <image> <source>/news/201 5/1.2.png</source> </image> <image> <source>/news/2015/1.3.jp g</source> </image> <image> <source>/news/2015/1.4.jpg</so urce> </image> <image> <source>/news/2015/1.5.jpg</source> </image> <image> <source>/news/2015/1.6.jpg</source> </image> <image> <source>/news/2015/1.7.jpg</source> < /image> <image> <source>/news/2015/1.8.png</source> </IMAGE&G T </images> </news></root>
The overall idea is to use Print_r for print debugging, encountered object is read with, encountered array on the [] read, in the debugging encountered in the Chinese code problem with the header ("content-type:text/html; Charset=utf-8 ");
Due to the limited personal level, commissioning took one hours, hope to see this blog less than half an hour debugging out.
<?PHP$xml=simplexml_load_file("Zh-cn/news.xml");Header("content-type:text/html; Charset=utf-8 ");foreach($xml as $news) { Echo $news[' ID ']. ' <br/> '; Echo $news[' Year ']. ' <br/> '; Echo $news->title. ' <br/> '; Echo $news->thumbnail. ' <br/> '; foreach($news->images->image as $image) { Echo $image->source. ' <br> '; }}?>
PHP uses simplexml_load_file to read XML-corresponding fields