Autor | Zpráva | ||
---|---|---|---|
matata8611 Profil |
#1 · Zasláno: 26. 8. 2014, 18:34:25
Ahoj, mam takovyto dotaz -> mám xml soubor naštený takto:
<?php $xml = simplexml_load_file($xml_soubor); ?> a v tomto tvaru <user> <user_id>112</user_id> <first_name>pepa</first_name> <last_name>vomáčka</last_name> </user> <user> <user_id>245</user_id> <first_name>lojza</first_name> <last_name>hromádka</last_name> </user> potřebuji vypsat přijmení uživatele s id 245 (vomáčka). Jak to mám prosím zavolat? |
||
Destiny_1 Profil |
a nepřemýšlel jsi o xml readru? Na větší soubory je rychlejší...
Tohle by ti mělo podle tvojí ukázky fungovat <?php class feed { private $adresa; private $set=array(); private $deal; public function __construct($adresa){ $this->adresa=$adresa; $this->set['user_id']=""; $this->set['first_name']=""; $this->set['last_name']=""; $this->deal="user"; $this->spustit(); } public function spustit(){ $xml = new XMLReader(); $xml->open($this->adresa); $pole=array(); while ($xml->read()) { if ($xml->nodeType == XMLReader::END_ELEMENT && $xml->name==$this->deal) { $this->ulozit($pole); $pole=array(); } if ($xml->nodeType == XMLReader::ELEMENT && isset($this->set[$xml->name])) { $pole[$xml->name]=trim($xml->readString()); } } } private function ulozit($string) { print_r($string); } } new feed("http://www.example.com/") a pokud budeš chtít vypsat pouze příjmení uživatele s id 245 tak si upravíš metodu ulozit <?php private function ulozit($string) { if ($string['user_id']==245) { echo $string['last_name']; } } ?> |
||
Časová prodleva: 11 let
|
0