PHP Remove Element from XML

后端 未结 3 2099
故里飘歌
故里飘歌 2021-01-24 03:10

I want to remove tasks that are older than today, but I can\'t quite figure out how to remove elements from XML file yet.

$xml_file = simplexml_load_file(\'file.         


        
3条回答
  •  旧巷少年郎
    2021-01-24 03:44

    Using simplexml: --> live demo @ http://codepad.viper-7.com/Jl16Oh

    $xml = simplexml_load_string($x); // XML is in $x
    
    $today = date("m/d/Y");
    $max = $xml->task->count()-1;
    
    for ($i = $max; $i >=0; $i--) {
    
       if ($xml->task[$i]->date < $today) unset($xml->task[$i]);
    
    }
    

提交回复
热议问题