php - Simple_XML Class: Getting attribute and information on the info node -


i pulling out information using ann api. used simplexml class information.

function explodetest() { $result = $this->_restgenerator($this->ann, '6236'); //print_r($result); foreach ($result->anime $data) { print_r($data->info); } } 

_restgenerator function:

function _restgenerator($url,$q) { $url = $url . strtolower($q); if(strlen($q) > 0) { $q = file_get_contents($url); //$q = simplexml_load_file($url) return simplexml_load_string($q); } } 

constants:

$this->ann = 'http://cdn.animenewsnetwork.com/encyclopedia/api.xml?anime='; 

when run function, :

simplexmlelement object ( [@attributes] => array ( [gid] => 3506750509 [type] => picture [src] => http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/a6236-259.jpg ) ) 

but actual xml tag displayed this:

<anime id="6236" gid="1601610894" type="tv" name="gintama" precision="tv" generated-on="2012-07-07t04:58:39z"> <info gid="3506750509" type="picture" src="http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/a6236-259.jpg"/> <info gid="1229282479" type="main title" lang="ja">gintama</info> <info gid="556528412" type="alternative title" lang="ru">Гинтама</info> <info gid="1383170257" type="alternative title" lang="ja">銀魂</info> <info gid="380581077" type="alternative title" lang="ko">은혼</info> <info gid="3483398015" type="genres">action</info> <info gid="1567209986" type="genres">adventure</info> <info gid="1221683927" type="genres">comedy</info> <info gid="3139902810" type="genres">drama</info> <info gid="2565080252" type="genres">fantasy</info> <info gid="971885680" type="genres">science fiction</info> <info gid="2312087995" type="objectionable content">ta</info> <info gid="1950277303" type="plot summary">...</info> <info gid="2741727987" type="running time">25</info> <info gid="3466023682" type="number of episodes">201</info> <info gid="2618069239" type="vintage">2006-04-04 2010-03-25</info> <info gid="820682777" type="vintage">2007-12-04 (italia, mtv italia)</info> <info gid="2490517434" type="vintage">2009-02-03 (spain, canal extremadura)</info> <info gid="1770356394" type="vintage">2009-08-30 (malaysia, tv2)</info> <info gid="2362558760" type="vintage">2010-01-18 (philippines, abs-cbn - team animazing)</info> <info gid="803932272" type="vintage">2011-03-23 (philippines - hero, league of heroes)</info> <info gid="2236361640" type="vintage">2011-04-04</info> <info gid="1161326503" type="opening theme">#1: "pray" tommy heavenly6 (eps 1-24)</info> <info gid="2241431608" type="opening theme">#2: "tooi nioi" yo-king (eps 25-49)</info> <info gid="1855414862" type="opening theme"> #3: "gin-iro no sora" (銀色の空; "silver sky") redballoon (eps 50-) </info> ... 

when print_r($result) ... info node displayed this

[info] => array ( [0] => simplexmlelement object ( [@attributes] => array ( [gid] => 3506750509 [type] => picture [src] => http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/a6236-259.jpg ) ) [1] => gintama [2] => Гинтама [3] => 銀魂 [4] => ì€í˜¼ [5] => action [6] => adventure [7] => comedy [8] => drama [9] => fantasy [10] => science fiction [11] => ta [12] => twenty years ago .. <synopsis> [13] => 25 [14] => 201 

i need type attribute of nodes array distinguishable, or @ least filter info node type attribute.

thanks.

use attributes function attributes.

foreach ($result->anime $data) { foreach($data->info $info){ $a = $info->attributes(); echo $a['type']. "\n"; } } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -