PHP:可以用\n替换\r\n吗?
我有一个带有文本区域和 JS 字符计数器的表单。然而后端脚本声称消息的 strlen 比 JS 字符计数器声明的长。我发现这样做的原因是后端将每个换行符视为 \r\n
这是两个字符。
我可以简单地让它执行 str_replace("\r\n","\n",$input)
吗?或者这会导致 Windows 用户看到字符串全部在一行上吗?我有什么理由不这样做吗?
I have a form with a textarea and a JS character counter. Yet the backend script claims that the strlen of the message is longer than the JS character counter claimed. The reason for this, I have discovered, is that the backend sees every newline character as \r\n
which is two characters.
Can I simply have it do a str_replace("\r\n","\n",$input)
? Or will this cause windows-users to see the string all on one line? Is there any reason why I should not do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
存储时仅使用
\n
是可以接受的。稍后解压时可以选择展开它。请注意,除\n
之前以外的其他位置的\r
可能具有其他意义,因此您不应盲目删除它的所有实例。When storing it is acceptable to only use
\n
. You may choose to expand it when extracting later. Note that a\r
in places other than just before a\n
may hold other significance and so you should not just blindly remove all instances of it.这听起来像是一件合理的事情......
That sounds like a reasonable things to do...