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.
关于\n 和\r 有太多的混淆。 堆栈中有很多关于 \n 和 \r 之间差异的问题。简而言之,我的困惑/问题是:
<BR>
并非所有字符串都明确具有 \r 或 \n。假设我有一个文本区域并且用户输入了一些字符,包括键盘的 Enter。未输入 \r 或 \n 但存在新行。如何删除所有新行?
微软视窗/MS-DOS: \r\n Acorn BBC 和 RISC OS 假脱机文本输出:\n\r Apple Macintosh OS 9 及更早版本:\r Unix(例如,Linux),还有 Apple OS X 和更高版本:\n
微软视窗/MS-DOS: \r\n
Acorn BBC 和 RISC OS 假脱机文本输出:\n\r
Apple Macintosh OS 9 及更早版本:\r
Unix(例如,Linux),还有 Apple OS X 和更高版本:\n
替换-> nl2br
更多关于这里
如果文本区域中存在新行而不是 \n、\r 或 \r\n!这些是不输出的控制字符。
要删除它们,您可以尝试:
$string = str_replace(array("\r\n", "\n\r", "\r", "\n"), "", $string);