开发者

I need to remove <p> tag to a field that only contains an URL

开发者 https://www.devze.com 2023-02-09 03:20 出处:网络
By mistake, I changed input by textareas, and wyswyg updated all the values like `http://google.com/?search=...` (url)to `<p>http://google.com/?search=..开发者_如何学C.</p>`

By mistake, I changed input by textareas, and wyswyg updated all the values like

`http://google.com/?search=...` (url)     to `<p>http://google.com/?search=..开发者_如何学C.</p>`

What correct mysql sentence can i use to fix this? PHP strip_tags() won't work :(


Maybe something like this:

UPDATE table SET column = REPLACE(column, "<p>", "");
UPDATE table SET column = REPLACE(column, "</p>", "");

Untested and possibly harmful !

Here's the reference:

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace


Something along these lines perhaps:

UPDATE tablename SET columnname = TRIM(LEADING '<p>' FROM TRIM(TRAILING '</p>' FROM columnname));

This might be faster:

UPDATE tablename SET columnname = TRIM(LEADING '<p>' FROM TRIM(TRAILING '</p>' FROM columnname)) WHERE columnname LIKE '<p>%</p>';

References:

TRIM (and other string functions)

LIKE (and other string comparison operators)

0

精彩评论

暂无评论...
验证码 换一张
取 消