输入来自文件。我正在使用此代码:
$inputText = "anbncnd";
$outputText = str_replace(PHP_EOL, ("<br />".PHP_EOL), $inputText);
输出为:
a
<br />b
<br />c
<br />d
<br />
但我需要:
a<br />
b<br />
c<br />
d<br />
有人可以帮我吗?
只需使用 nl2br()
。
这将为您完成所有工作。无需手动替换。
$outputText = nl2br($inputText);
只需尝试:
$outputText = str_replace("n", "<br />n", $inputText) . '<br />';
您可以使用preg_replace()
吗?
$outputText = preg_replace("/n|$/", "<br />".PHP_EOL, $inputText);