Portál AbcLinuxu, 9. května 2025 23:16
$xml = simplexml_load_string("<users> <jmeno>Karel</jmeno> <jmeno>Pavel</jmeno> <jmeno>Libor</jmeno> <jmeno>Marek</jmeno>> </users>"); echo $xml->users;
<?php $xml = simplexml_load_string(<<<EOT <users> <jmeno>Karel</jmeno> <jmeno>Pavel</jmeno> <jmeno>Libor</jmeno> <jmeno>Marek</jmeno> </users> EOT ); print_r($xml->jmeno);
print_r($xml->jmeno);
foreach ($xml->users as $user){ print (string) $user; }U simplexml je potřeba hlavně pochopit jak se co zapisuje a co to ve skutečnosti dělá, nevím jestli to bude hned zkraje srozumitelné, nicméně je to takto:
1) properties denote element iterators 2) numeric indices denote elements 3) non numeric indices denote attributes 4) string conversion allows to access TEXT 5) xpath returns simple array of elements Warning! Assign notation $oEl{'elm'} = 'content'; handle properly xml special characters, but method notation $oEl->addChild('elm', 'content'); NOT HANDLE special xml characters!
Ten příklad funguje, pokud, děláte někde chybu.Pardon, mělo to být
Ten příklad funguje, pokud ne, děláte někde chybu.
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.