PHP's strip_tags() equivalent MYSQL function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

PHP's strip_tags() equivalent MYSQL function

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP's strip_tags() equivalent MYSQL function

Post 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]
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: PHP's strip_tags() equivalent MYSQL function

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: PHP's strip_tags() equivalent MYSQL function

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP's strip_tags() equivalent MYSQL function

Post by requinix »

No such function.

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