remove new line characters from txt file using php

前端 未结 4 1189
南方客
南方客 2020-12-06 11:02

I have txt file its content like this

Hello  
World   
John  
play  
football  

I want to delete the new line character when reading this

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 12:02

    If your going to be putting the lines into an array, an assuming a reasonable file size you could try something like this.

    $file = 'newline.txt';      
    $data = file_get_contents($file);   
    $lines = explode(PHP_EOL, $data);  
    
    /** Output would look like this
    
    Array
    (
        [0] => Hello  
        [1] => World   
        [2] => John  
        [3] => play  
        [4] => football  
    )
    
    */
    

提交回复
热议问题