PDA

View Full Version : [PHP][XML] Need a bit of help.



Garden of Sinners
07-24-2016, 08:12 PM
Hello there I've been trying to sort the data I've been pulling from a generated XML file and could use some help with alphabetizing the title_series.



<?php
$user= "domokun1134";

$urlss = 'http://myanimelist.net/malappinfo.php?u=' . $user . '&status=all&type=anime';

$xmlss = simplexml_load_file($urlss);
$jsossn = json_encode($xmlss);
$arrayss = json_decode($jsossn,TRUE);

usort($arrayss, function($a, $b){
return strcasecmp($a[1]["series_title"], $b[1]["series_title"]);
});

echo "<pre>";
print_r($arrayss);
echo "</pre>";

?>

onilika
07-24-2016, 09:42 PM
Hello there I've been trying to sort the data I've been pulling from a generated XML file and could use some help with alphabetizing the title_series.



<?php
$user= "domokun1134";

$urlss = 'http://myanimelist.net/malappinfo.php?u=' . $user . '&status=all&type=anime';

$xmlss = simplexml_load_file($urlss);
$jsossn = json_encode($xmlss);
$arrayss = json_decode($jsossn,TRUE);

usort($arrayss, function($a, $b){
return strcasecmp($a[1]["series_title"], $b[1]["series_title"]);
});

echo "<pre>";
print_r($arrayss);
echo "</pre>";

?>


I'm working on something similar to that, but in my case i have a json file, not an xml. And since you want to decode an XML, why you using json_encode and json_decode?

edit: oh I see..

Lucidity
07-25-2016, 07:51 AM
use the PHP function


Sort($array);

in your case:


<?php
$user= "domokun1134";

$myURL = 'http://myanimelist.net/malappinfo.php?u=' . $user . '&status=all&type=anime';

$xmlLoadFile = simplexml_load_file($myURL);
$jEncode = json_encode($xmlLoadFile);
$jDecode = json_decode($jEncode,TRUE);
sort($jDecode);

foreach ($jDecode as $key => $val) {
echo('<pre>'.$val.'</pre>\n');
}

?>


correct me if I am wrong, but that should work for listing it in alphabetical order..