Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在从 textarea 向 MySQL 数据库添加文本。所有换行符都转换为 \r\n 我可以使用以下 scipt 在 html 中正确显示新行:
function solver_nl2br($e){ $output = str_replace("\\r\\n", "<br/>", $e); return $output; }
但是当我试图在 textarea 中编辑文本时,我所能看到的只是\r\n新行。
\r\n
我可以使用什么功能在 textarea 中显示换行符而不是换行符?
试试这个,
$output = nl2br(htmlenitites($e));
使用本机功能nl2br()。它将捕获更多情况:(\r\n、\n\r、\n 和 \r)。仅供参考:新行 PHP_EOL 也有常量。您希望您的代码尽可能在 Windows 或 Linux 上运行良好。
nl2br()
试试这个:
$output = str_replace("\\r\\n", "\n", $e);