View Full Version : PHP's strip_tags() equivalent MYSQL function

01-15-2010, 12:40 PM
Hello forums!
I was just wondering to know how this can be accomplished:

SELECT * FROM cms_pages WHERE body LIKE '%keywords%';
Problem: Suppose my keyword=font & body field contains:

<div style="font-size:12px">This is a body area</div>
then above query fetches this row.

I would like to know,
is there any function to strip the html tags while executing query?
something like:

SELECT * FROM cms_pages WHERE strip_tags(body) LIKE '%keywords%';
or by any other means?


01-15-2010, 01:57 PM
I don't think so. Why can't you just do this when you are getting the data from the db?

01-15-2010, 06:44 PM
MySQL does not natively support expression replacement. It can find matches, but not capture them for replacement.

Just out of curiosity I did a google search for "mysql strip_tags" and "mysql regex replace", only to find that half the first page results are you having copied/pasted this question on at least 5 other forums. ;)

As already suggested here and in many of the replies in other locations, I'd agree it would be best to store the data twice, once as the original and once in another column (or table w/ a foreign key) with the tags stripped using PHP.