note 83277 deleted from ref.xml by danbrown

From: Date: Wed, 03 Mar 2010 18:57:08 +0000
Subject: note 83277 deleted from ref.xml by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166633@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- This is peace of the code. It edit xml file. <? $songs = Array(); function start_element($parser, $name, $attrs){ global $songs; if($name == "song"){ array_push($songs, $attrs); } } function end_element ($parser, $name){} $playlist_string = file_get_contents("test.xml"); $parser = xml_parser_create(); xml_set_element_handler($parser, "start_element", "end_element"); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parse($parser, $playlist_string) or die("Error parsing XML document."); print "<br />"; if($_POST['action'] == "ins"){ array_push($songs, Array( "title" => $_POST['title'], "artist" => $_POST['artist'], "path" => $_POST['path'])); $songs_final = $songs; }else if($_POST['action'] == "del"){ $songs_final = Array(); foreach($songs as $song){ if($song['title'] != $_POST['title']){ array_push($songs_final, $song); } } } $write_string = "<songs>"; foreach($songs_final as $song){ $write_string .= "<song>"; $write_string .= "<title>".$song['title']."</title>"; $write_string .= "<artist>".$song['artist']."</artist>"; $write_string .= "<path>".$song['path']."</path>"; $write_string .= "</song>"; } $write_string .= "</songs>"; $fp = fopen("test.xml", "w+"); fwrite($fp, $write_string) or die("Error writing to file"); fclose($fp); print "<em>Song inserted or deleted successfully :)</em><br />"; print "<a href=\"index.php\" title=\"return\">Return</a>"; ?>

« previous php.notes (#166633) next »