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

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

Bubble Sort Manually a Linked List in Java -

asp.net mvc - SSO between MVCForum and Umbraco7 -