How to get attribute on a 'XML' string in PHP -
i have string..
'<tag k="addr:country" v="uy"/>'
i want make string array like
array( "k" => "addr:country", "v" => "uy" )
i planning explode ' ' , explode again charater '=' , form array, dont think code. wondering if there better way of extracting attribute string.
thanks in advance/
you use simplexml:
$input = '<doc><tag k="addr:country" v="uy"/></doc>'; $xml = simplexml_load_string($input); foreach($xml->tag[0]->attributes() $a => $b) { print "$a => $b \r\n"; }
this return
k => addr:country v => uy
Comments
Post a Comment