将换行符替换为'\ n'
问题描述:
我需要使用\ n替换mysql数据库中的换行符的帮助. 如果我在MS Word中复制mysql文本和过去的内容,则有以下内容:
I need help for replacing line breaks in my mysql database with \n. If I copy mysql text and past in MS Word, I have this:
我需要将换行符替换为\ n.像这样:
I need to replace the break lines with \n. Like this:
对此有任何MySql命令以及一个PHP或Javascript函数吗?
There are any MySql command for this and one PHP or Javascript function?
谢谢.
答
在Php中,有一个名为nl2br
In Php there is a function named nl2br
echo nl2br("hello\nWorld");
结果是
hello<br/>World
在sql中,有一个名为REPLACE
In sql there is a function named REPLACE
UPDATE yourtable SET field=REPLACE(REPLACE(field, CHAR(13), ''), CHAR(10), '')
最后在javaScript中您也有replace
And Finally in javaScript you have replace
too
myString = myString.replace(/\r?\n/g, "");
祝你好运