Page 1 of 1

PHP's strip_tags() equivalent MYSQL function

Posted: Fri Jan 15, 2010 5:40 am
by PHPycho
Hello forums!
I was just wondering to know how this can be accomplished:
Case:

Code: Select all

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

Code: Select all

<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:

Code: Select all

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

Thanks

Re: PHP's strip_tags() equivalent MYSQL function

Posted: Fri Jan 15, 2010 6:08 am
by VladSun
I don't think there is such a function in MySQL.
Why don't you just reverse it:
[sql]SELECT * FROM cms_pages WHERE body LIKE '%keywords_tag_stripped%';[/sql]

Re: PHP's strip_tags() equivalent MYSQL function

Posted: Fri Jan 15, 2010 6:31 am
by PHPycho
Consider my case and see what if your's keywords_tag_stripped = 'font' (which itself is stripped btw)
I dont think this approach will work.

Re: PHP's strip_tags() equivalent MYSQL function

Posted: Fri Jan 15, 2010 6:42 am
by VladSun
Well, words like "font", "body", etc. found in HTML tags can't be considered content, but meta data...
Please, explain what you are trying to achieve.

Re: PHP's strip_tags() equivalent MYSQL function

Posted: Fri Jan 15, 2010 7:31 am
by requinix
No such function.

Keep a second field for the strip_tag'd data and search against that.