用PHP中的换行输出文本文件 [英] Output text file with line breaks in PHP
本文介绍了用PHP中的换行输出文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图打开一个文本文件并使用下面的代码输出它的内容。文本文件包含换行符,但是当我回显未格式化的文件时。
$ b
< html> ;
< head>
< / head>
< body>
$ fh = fopen(filename.txt,'r');
$ pageText = fread($ fh,25000);
echo $ pageText;
< / body>
< / html>
解决方案
将纯文本换行符转换为html换行符,试试这个:
$ fh = fopen(filename.txt,'r');
$ pageText = fread($ fh,25000);
echo nl2br($ pageText);
请注意包装文本的nl2br函数。
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?
Thanks.
<html>
<head>
</head>
<body>
$fh = fopen("filename.txt", 'r');
$pageText = fread($fh, 25000);
echo $pageText;
</body>
</html>
解决方案
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.
这篇关于用PHP中的换行输出文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文