Skip to content

Instantly share code, notes, and snippets.

@sandeepwisetr
Created January 24, 2015 06:47
Show Gist options
  • Save sandeepwisetr/ed8bc4af6f930c046bfc to your computer and use it in GitHub Desktop.
Save sandeepwisetr/ed8bc4af6f930c046bfc to your computer and use it in GitHub Desktop.
XML to array conversion using recursive programing method
$site_url = site_url().'/xmltophp/jobsfeed.xml';
//echo $site_url;
$xml = simplexml_load_file($site_url);
$ar = xml2array($xml);
function xml2array($xml) {
$arr = array();
foreach ($xml->children() as $r) {
if (count($r->children()) == 0) {
$arr[$r->getName()] = strval($r);
} else {
$arr[$r->getName()][] = xml2array($r);
}
}
return $arr;
}
use as
$ar['job']['title']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment