2016-12-02 29 views

回答

0

這很簡單。你可以像下面的代碼一樣實現。

<?php 

    $lines = file('text.txt', FILE_IGNORE_NEW_LINES); 
    $five_line_array = array_splice($lines, 0, 5); 

    $data = implode("\n", array_values($lines)); 

    $file = fopen('text.txt', "w+"); 
    fwrite($file, $data); 
    fclose($file); 

    print_r($five_line_array); // output as Array ([0] => google [1] => yahoo [2] => bing [3] => msn [4] => soso) 
+0

它的工作,謝謝這個代碼中的唯一問題是在單行程中斷'\ n'它應該是雙引號「\ n」,那麼它會工作。再次感謝。 –

+0

@HarshSharma。是啊,你說得對。我沒有在測試中立即寫出答案文本框中的代碼。對不起,我的錯誤。我編輯了答案。很高興我能幫助你。 –

相關問題