note 83277 added to ref.xml

From: Date: Sun, 18 May 2008 19:18:12 +0000
Subject: note 83277 added to ref.xml
Groups: php.notes 
Request: Send a blank email to php-notes+get-139506@lists.php.net to get a copy of this message
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>"; ?> ---- Server IP: 217.174.223.124 Probable Submitter: 81.56.106.150 ---- Manual Page -- http://www.php.net/manual/en/ref.xml.php Edit -- https://master.php.net/note/edit/83277 Del: integrated -- https://master.php.net/note/delete/83277/integrated Del: useless -- https://master.php.net/note/delete/83277/useless Del: bad code -- https://master.php.net/note/delete/83277/bad+code Del: spam -- https://master.php.net/note/delete/83277/spam Del: non-english -- https://master.php.net/note/delete/83277/non-english Del: in docs -- https://master.php.net/note/delete/83277/in+docs Del: other reasons-- https://master.php.net/note/delete/83277 Reject -- https://master.php.net/note/reject/83277 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139506) next »