2017-04-13 3 views
-1

Ä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); } 
} 

?> 
+0

mit [fwrite] (http://php.net/fwrite) – hassan

+0

Sie geben nur sehr wenig Informationen über Ihre Daten. Welche Variable enthält die Daten, die Sie speichern möchten? – Manngo

Antwort

0

Entschuldigen Sie mich, aber wahrscheinlich wegen der Google Übersetzer oder weil sie daran gehindert werden, aber Sie werden wahrscheinlich nicht verstehen, habe ich es:

<?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); } 
    } 


    // open your new file 
    $newFile = fopen('newmenu2.txt', 'w'); 

    // write to your file using $newFile file handler, 
    // with the imploded data you want to write into your file 
    fwrite($newFile, implode("\n", $data)); 

    // close your file handler 
    fclose($newFile); 
    ?> 

Hinweis: Nicht definierte Variable: Daten auf der Leitung 29

Warning: implode(): Invalid line gebenen Argumente auf 29

Verwandte Themen