XML parsing conundrum

后端 未结 7 1408
甜味超标
甜味超标 2021-01-15 22:25

UPDATE: I\'ve reworked the question, to show progress I\'ve made, and maybe make it easier to answer.

UPDATE 2: I\'ve added another value to the XML. Extension avail

7条回答
  •  借酒劲吻你
    2021-01-15 22:48

    This is the code that will give you the result you need. UPDATE: This concerns the latest grouping you asked for.

    $scrape_xml = "files.xml";
    $xml = simplexml_load_file($scrape_xml);
    $groups = array();
    
    foreach ($xml->Item as $file){
        $platform = stripslashes($file->Platform);
        $name = stripslashes($file->Name);
        $title = stripslashes($file->Title);
        $extensions = explode('    ', $file->Ext);
    
        foreach($extensions as $extension)
        {
            if (!isset($groups2[$platform])) $groups2[$platform] = array();
            if (!isset($groups2[$platform][$extension])) $groups2[$platform][$extension] = array();
    
            $groupFound = false;
            for($idx = 0; $idx < count($groups2[$platform][$extension]); $idx ++) {
                if ($groups2[$platform][$extension][$idx]["Name"] == $name 
                    && $groups2[$platform][$extension][$idx]["Title"] == $title) {
    
                    $groups2[$platform][$extension][$idx]["Files"][] =
                        array('DownloadPath' => $file->DownloadPath."");
    
                    $groupFound = true;
    
                    break;
                }
            }
    
            if ($groupFound) continue;
    
            $groups2[$platform][$extension][] = 
                array(
                    "Name" => $name,
                    "Title" => $title,
                    "Files" => array(array('DownloadPath' => $file->DownloadPath."")));
        }
    }
    
    echo "
    "; echo "
    ";
    print_r($groups2);
    echo "
    ";

提交回复
热议问题