我有一个基本的PHP页面,列出了数据库中的记录,每行一条。
目前,我正在使用<br>
移到下一行,但我确实需要用回车来代替它,这样它就可以像文本文件一样从外部读取。
有办法做到这一点吗?
可以。如果要将其用作文本文件,可以将标题text/plain
与回车符结合使用。
<?php
header("Content-Type:text/plain");
echo 'Rule 1'. "'r"; //*Note the dubble quote!*
echo 'Rule 2'. "'r"; //*Note the dubble quote!*
?>
编辑:在Matt Gibsen 的(有用的)评论之后
您也可以使用与"''n"的组合,如:
echo 'Rule 1'. "'r'n"; //*Note the dubble quote!*
何时使用'n
、'r
或'r'n
取决于操作系统:
- Linux/Unix:''n
- Windows:''r''n