In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "php how to read remote xml files and convert them into arrays". The content in the article is simple and clear, and it is easy to learn and understand. Please follow Xiaobian's train of thought to study and learn "php how to read remote xml files and convert them into arrays".
Php reads remote xml files and converts them into arrays: 1, create a PHP sample file; 2, get xml objects through "simplexml_load_file"; 3, convert data objects into arrays in a loop.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How does php read remote xml files and convert them to arrays?
PHP reads the remote xml file and converts it to an array:
The remote file is as follows: http://api.wycq.521g.com/game/mrt_consume/xyg, open is a xml file, the content is a game top-up ranking and different ranking reward information, you need to take out the top ten information and reward information for display
The implementation code is as follows:
Public function index () {$url = "http://api.wycq.521g.com/game/mrt_consume/xyg"; $contentxml = simplexml_load_file ($url); / / get the xml object, which needs to be converted into an array of $ranks = array (); for ($itemistanding-> player [$I]; / / loop converts bar ranking data objects into an array of $ranks [$item1] = $temp_player ['@ attributes']) / / fetch the corresponding attribute values in the array} $awards = array (); for ($ipri0bot awards-> award [$I]; / loop convert the award data object into an array} $res_awards = array (); foreach ($awards as $k = > $v) {$res_awards [$k] ["caption"] = $v ['@ attributes'] ["caption"] / / further processing to clean the array $res_awards [$k] ["items"] = array (); foreach ((array) $v ["items"] as $m = > $n) {$res_awards [$k] ["items"] = $n;} for ($jack0 ) {$temp_q = (array) $Q; $res_awards [$j] ["items"] [$p] = $temp_q ['@ attributes'];}} $this- > _ data ["ranks"] = $ranks; $this- > _ data ["res_awards"] = $res_awards $this- > load- > view ('hd/wymingrentang/wymingrentang', $this- > _ data) / / specify view page output data} Thank you for reading, this is the content of "how php reads remote xml files and converts them into arrays". After the study of this article, I believe you have a deeper understanding of how php reads remote xml files and convert them into arrays. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.