I am pulling out information using the ANN api. I used the simpleXML class to get the information.
function explodeTest() {
$result = $this->_restGenerator($this->ann, '6236');
//print_r($result);
foreach ($result->anime as $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 I run the function, I get this :
SimpleXMLElement Object ( [@attributes] => Array ( [gid] => 3506750509 [type] => Picture [src] => http://cdn.animenewsnetwork.com/thumbnails/fit200x200/encyc/A6236-259.jpg ) )
But the actual XML tag is displayed as 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 to 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" by Tommy Heavenly6 (eps 1-24)</info>
<info gid="2241431608" type="Opening Theme">#2: "Tooi Nioi" by YO-KING (eps 25-49)</info>
<info gid="1855414862" type="Opening Theme">
#3: "Gin-iro no Sora" (銀色の空; "Silver Sky") by redballoon (eps 50-)
</info> ...
When i do print_r($result) … the info node is displayed as 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 to get the type attribute of the nodes to get the array to be distinguishable, or at least filter the info node by type attribute.
Thanks.
Use the attributes function to get the attributes.