How do you perform the following PHP function in MySQL using UPDATE
, SET
and REPLACE
?
preg_replace('/\s+/', ' ', $string);
from Remove multiple whitespaces
EDIT QUESTION
My objectif is to go from the follwing 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]
to the above
[!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]
clearing all the \r \n \t
\n = new line \r = carriage return \t = tab
EDIT ANSWER
The full answer using UPDATE
, SET
and REPLACE
in addition to Elias Van Ootegem's suggestion
UPDATE tab
SET col = REPLACE(
REPLACE(
REPLACE(
REPLACE(col, '~', ''),
'\t', '' -- replace tabs
),
'\n','' -- replace *NIX line-feeds
),
'\r', -- replace DOS line-feeds
''
)