PHP在插入MySQL之前删除换行符

PHP在插入MySQL之前删除换行符,php,mysql,Php,Mysql,我已经搜索了几天来修复此问题: 我无法从字符串中删除换行符。 我所做的一切: 致以最良好的祝愿, 罗尼使用 好的,那么使用下面的函数。这可能也可以用preg_replace完成,但这里是str_replace function replaceWithBr($str) { $str = trim($str); $str = str_replace("\r\n", "[br]", $str); $str = str_replace("\r", "[br]", $str);

我已经搜索了几天来修复此问题:

我无法从字符串中删除换行符。 我所做的一切:

致以最良好的祝愿, 罗尼

使用


好的,那么使用下面的函数。这可能也可以用preg_replace完成,但这里是str_replace

function replaceWithBr($str)
{
    $str = trim($str);
    $str = str_replace("\r\n", "[br]", $str); 
    $str = str_replace("\r", "[br]", $str); 
    $str = str_replace("\n", "[br]", $str);  
    return $str;
}
$text = "hello
test

more lines,
Thanks,
";

echo $text."<br >";
echo replaceWithBr($text)."<br >";
函数replaceWithBr($str)
{
$str=修剪($str);
$str=str\u replace(“\r\n”、“[br]”、$str);
$str=str\u替换(“\r”、“[br]”、$str);
$str=str\u替换(“\n”、“[br]”、$str);
返回$str;
}
$text=“你好
测验
多行,,
谢谢
";
回显$text.“
”; 回声替换为br($text)。“
”;
$string=trim(preg_replace('/\s+/',''$string));您可以发布
$\u post['replytext']
?@OrlandoP。这也会删除空格吗?我在之前尝试了s+(一些代码但没有修剪).Trim只是不这样做。
\s+
是一个或多个空格,不特定于新行。@ronnieoutting yes正则表达式考虑单词之间和单词后面的空格。Trim只考虑字符串后面的空格,而不考虑字符串之间的空格。如果新行是新行,这不会剥离新行。嗨,Arun,strip_标记看起来非常适合secur城市结尾,但不适用于文本区域中的新行(回车按钮)文本之间的新行如何?用户可以发布例如:(嗨,用户,(回车)你好吗?(回车)@OP-Hi也给你。这只是随机的,你可以注意到,哈哈。文本区域中的回车需要用[br]替换nl2br应该注意在这些新行之前添加
,而不是在MySQL中添加新行。是否要完全删除新行?您好,Amit,所有新行都需要替换为[br]。按文本区域中的“回车”按钮创建的所有新行。我已根据您的评论编辑了我的答案。检查是否有效。阿米特,谢谢!!!!!有效!最后。非常感谢。将您的答案标记为答案
<br />
<br />
testt
This is my reply. blabla

Some new lines, and now the quoted text below:

[quote=DaSP date=2017-08-07 17:42:37]dsaasdasd[br][br]asdasd[br][br]asd[br]asd[br][br][quote=DaSP date=2017-08-07 17:42:28]asd[br][br][quote=DaSP date=2017-08-07 17:16:06][br][br]fg[/quote][/quote][/quote]
echo strip_tags("Hello <b><i>world!</i></b>");
$string = trim(preg_replace('/\s+/', ' ', $string));
function replaceWithBr($str)
{
    $str = trim($str);
    $str = str_replace("\r\n", "[br]", $str); 
    $str = str_replace("\r", "[br]", $str); 
    $str = str_replace("\n", "[br]", $str);  
    return $str;
}
$text = "hello
test

more lines,
Thanks,
";

echo $text."<br >";
echo replaceWithBr($text)."<br >";