Preserve linebreak txt php

前端 未结 2 396
余生分开走
余生分开走 2021-01-03 10:46

How can I read a .txt file from my server, and preserve it\'s linebreaks? Note that the linebreaks aren\'t like this /n or something, they are more

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-03 11:32

    For output? Just use nl2br

    $file = file_get_contents( 'file.txt' );
    echo nl2br( $file );
    

    Also works with fopen.

提交回复
热议问题