PHP:可以用\n替换\r\n吗?

发布于 2024-08-18 17:00:45 字数 227 浏览 2 评论 0原文

我有一个带有文本区域和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£烟消云散 2024-08-25 17:00:45

存储时仅使用 \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.

幻想少年梦 2024-08-25 17:00:45

这听起来像是一件合理的事情......

That sounds like a reasonable things to do...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文