2016-12-02 70 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。是啊,你说得对。我没有在测试中立即写出答案文本框中的代码。对不起,我的错误。我编辑了答案。很高兴我能帮助你。 –

相关问题