2017-04-13 6 views
-1

このスクリプトでは、テキストファイル内の行の順番を変更しますが、ファイルを新しいファイルとして保存します。どうやってやるの?スクリプトで行った変更を保存する方法

<?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

に渡された無効な引数(http://php.net/fwrite) – hassan

+0

あなたはあなたのデータについてほとんど情報を提供します。保存したいデータを保持する変数はどれですか? – Manngo

答えて

0

はなく、おそらくGoogleの翻訳のか、それらが防止されるので、恐れ入りますが、あなたはおそらく、私はそれをしなかった、それを理解できないだろう。

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

注意:未定義の変数:ライン上のデータ29

警告:破():[fwriteの]を使用してライン29

関連する問題