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 和 JS 字符计数器的表单。然而后端脚本声称消息的 strlen 比 JS 字符计数器声称的长。我发现这样做的原因是后端将每个换行符视为\r\n两个字符。
\r\n
我可以简单地让它做一个str_replace("\r\n","\n",$input)吗?或者这会导致 Windows 用户在一行上看到所有字符串?有什么理由我不应该这样做吗?
str_replace("\r\n","\n",$input)
储存时只使用\n. 您可以在以后提取时选择扩展它。请注意,a\r在 a 之前以外的位置\n可能具有其他意义,因此您不应盲目地删除它的所有实例。
\n
\r
这听起来像是一个合理的事情......