This question already has an answer here:
这个问题在这里已有答案:
- Doing calculations in MySQL vs PHP 5 answers
- 在MySQL和PHP 5中做计算答案
I have a question, what is the most optimal way for replace the strings for example, I want to replace \n and \r\n with ''. I have 2 options :
我有一个问题,例如,替换字符串的最佳方法是什么,我想用''替换\ n和\ r \ n。我有2个选择:
-
Replaces nested:
替换嵌套:
SELECT REPLACE(REPLACE(m3.old_message,'\n',''),'\r\n','')
SELECT REPLACE(REPLACE(m3.old_message,'\ n',''),'\ r \ n','')
-
Preg replace:
Preg替换:
if ($aField== 'user') { $sValue = preg_replace... }
if($ aField =='user'){$ sValue = preg_replace ...}
Thx in advance.
Thx提前。
1 个解决方案
#1
1
In PHP you can do:
在PHP中,您可以:
$string = preg_replace('/\R/', '.', $string);
Where \R
stands for any line break, \r
or \n
or \r\n
.
其中\ R代表任何换行符,\ r或\ n或\ r \ n。
#1
1
In PHP you can do:
在PHP中,您可以:
$string = preg_replace('/\R/', '.', $string);
Where \R
stands for any line break, \r
or \n
or \r\n
.
其中\ R代表任何换行符,\ r或\ n或\ r \ n。