Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 正在将\n转换为<;br/>;_Php - Fatal编程技术网

Php 正在将\n转换为<;br/>;

Php 正在将\n转换为<;br/>;,php,Php,可能重复: 如何在文件的每行附加标记,因为HTML中无法识别\n。 例如,文件的内容是: A B C D html中的输出只是 ABCD 或者是否有更好的方法,比如用替换\n?只需使用将所有换行符转换为即可,只需在保存内容之前使用即可。它将用替换所有“\n”: file_put_contents('./files/'.$count.'.txt',nl2br($input)); 正如其他人所建议的,如果只需要添加标记,只需将字符串传递给nl2br() 如果您想在每行末尾添加另一个字符串,或者

可能重复:

如何在文件的每行附加

标记,因为HTML中无法识别\n。 例如,文件的内容是:

A
B
C
D
html中的输出只是

ABCD

或者是否有更好的方法,比如用

替换
\n

只需使用将所有换行符转换为

即可,只需在保存内容之前使用即可。它将用

替换所有
“\n”

file_put_contents('./files/'.$count.'.txt',nl2br($input));

正如其他人所建议的,如果只需要添加

标记,只需将字符串传递给
nl2br()

如果您想在每行末尾添加另一个字符串,或者在添加

时保留换行符,您可以执行以下操作:

$appendStr = "arbitrary string you wish to append";
$rows = explode("\n", $str);
$contents = implode ( $appendStr . "\n", $rows );

哇,我没想到。谢谢你的快速帮助!没问题。你可能想考虑把问题的标题稍微改变一下,以便更好地反映问题和答案。
$appendStr = "arbitrary string you wish to append";
$rows = explode("\n", $str);
$contents = implode ( $appendStr . "\n", $rows );