【发布时间】:2013-10-06 08:47:50
【问题描述】:
您如何使用UPDATE、SET 和REPLACE 在MySQL 中执行以下PHP 函数?
preg_replace('/\s+/', ' ', $string);
编辑问题
我的目标是从以下字符串开始
[!DOCTYPE html]
[!--[if IE 8]][html class="no-js lt-ie9" lang="es" ][![endif]--]
[!--[if gt IE 8]][!--] [html class="no-js" lang="es" ] [!--[![endif]--]
[html lang="es-ES" prefix="og: http://ogp.me/ns#"]
[head]
以上
[!DOCTYPE html][!--[if IE 8]][html class="no-js lt-ie9" lang="es" ][![endif]--]
[!--[if gt IE 8]][!--][html class="no-js" lang="es" ][!--[![endif]--][html lang="es-ES" prefix="og: http://ogp.me/ns#"][head]
清除所有\r \n \t
\n = 换行 \r = 回车 \t = 制表符
编辑答案
除了 Elias Van Ootegem 的建议之外,使用 UPDATE、SET 和 REPLACE 的完整答案
UPDATE tab
SET col = REPLACE(
REPLACE(
REPLACE(
REPLACE(col, '~', ''),
'\t', '' -- replace tabs
),
'\n','' -- replace *NIX line-feeds
),
'\r', -- replace DOS line-feeds
''
)
【问题讨论】:
-
你试过了吗……这个问题有成千上万的骗子:stackoverflow.com/questions/6858143/…
-
这不是我想要的...
-
添加了答案,希望这就是你所追求的
标签: mysql replace tabs whitespace carriage-return