Ändern Sie mit diesem Skript die Reihenfolge der Zeilen in einer Textdatei, aber ich möchte die Datei als neue Datei speichern. Wie kann ich das machen?So speichern Sie die mit einem Skript vorgenommenen Änderungen
<?php
$file = "menu2.txt";
$righe = file($file);
$numrighe = count($righe);
$portieri = array();
$difensori = array();
$aladestra = array();
$alasinistra = array();
$attaccante = array();
for($i=0; $i < $numrighe;$i++) {
$riga = $righe[$i];
list($giocatore, $ruolo) = preg_split("[>]", $riga);
if(strcmp($ruolo,"Portiere")) { array_push($portieri, $giocatore); }
else if(strcmp($ruolo,"Difensore")) { array_push($difensori, $giocatore); }
else if(strcmp($ruolo,"Ala destra")) { array_push($aladestra, $giocatore); }
else if(strcmp($ruolo,"Ala sinistra")) { array_push($alasinistra, $giocatore); }
else if(strcmp($ruolo,"Attaccante")) { array_push($attaccante, $giocatore); }
}
?>
mit [fwrite] (http://php.net/fwrite) – hassan
Sie geben nur sehr wenig Informationen über Ihre Daten. Welche Variable enthält die Daten, die Sie speichern möchten? – Manngo