I've never used simplexml_load_string()
before, so I thought I'd take the opportunity to self-educate.
After a combination of reading Doomenik's posted link, reading the manual on simplexml_load_string()
, and running some tests on 3v4l.org, this seems to be a direct/advisable solution:
Code: (Demo)
$result='<?xml version="1.0" encoding="UTF-8"?> <PrintLetterBarcodeData uid="123" name="Demo Name" gender="M" yob="2000" gname="Abdul Mannan" lm="city" vtc="City2" po="norway" dist="california" subdist="Ny" state="US" pc="12345" dob="22/06/2000"/>';
$array=json_decode(json_encode(simplexml_load_string($result)),true);
foreach($array['@attributes'] as $k=>$v){
echo "<div>$k : $v</div>\n";
}
Output:
<div>uid : 123</div>
<div>name : Demo Name</div>
<div>gender : M</div>
<div>yob : 2000</div>
<div>gname : Abdul Mannan</div>
<div>lm : city</div>
<div>vtc : City2</div>
<div>po : norway</div>
<div>dist : california</div>
<div>subdist : Ny</div>
<div>state : US</div>
<div>pc : 12345</div>
<div>dob : 22/06/2000</div>