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我的形式
textarea
当用户输入Enter键时,它将存储\n到数据库中
\n
我应该允许\n存储到 mySql 数据库中吗?或者我应该这样str_replace做,如果用户输入abc\n\n\n\n\n\n\n\n大量Enter,有什么方法可以修剪 \n前端和末端
str_replace
abc\n\n\n\n\n\n\n\n
这取决于你想对数据做什么。如果你想允许多个换行符,那就去做吧!如果你不那么不要!以下是一些可能对您有所帮助的代码:
// trim leading and trailing line breaks, spaces, tabs, etc. $string = trim($string); // Replace multiple line breaks with one: $string = preg_replace("/\n+/", "\n", $string);