Output text file with line breaks in PHP

前端 未结 9 1057
一个人的身影
一个人的身影 2020-11-28 14:11

I\'m trying to open a text file and output its contents with the code below. The text file includes line breaks but when I echo the file its unformatted. How do I fix this?<

9条回答
  •  春和景丽
    2020-11-28 14:59

    To convert the plain text line breaks to html line breaks, try this:

        $fh = fopen("filename.txt", 'r');
    
        $pageText = fread($fh, 25000);
    
        echo nl2br($pageText);
    

    Note the nl2br function wrapping the text.

提交回复
热议问题