Re: Mysql search html tags excluded
| From: | Ashley Sheridan | Date: | Fri, 04 Jun 2010 11:52:22 +0000 |
| Subject: | Re: Mysql search html tags excluded | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-305808@lists.php.net to get a copy of this message | ||
On Fri, 2010-06-04 at 14:44 +0300, Tanel Tammik wrote:
> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message
> news:1275651371.2217.46.camel@localhost...
> > On Fri, 2010-06-04 at 14:12 +0300, Tanel Tammik wrote:
> >
> >> Hello,
> >>
> >> if there is some webpage content with html tags in database is it
> >> possible
> >> to search it without tags?
> >>
> >> data : '<div style="">you need some styling!</div>'
> >>
> >> when i now search for 'you style' i don't want to get any rows! is it
> >> possible?
> >> when i search 'you styling' i get the row!
> >>
> >> Br
> >> Tanel
> >>
> >>
> >>
> >
> >
> > Use a second field in the DB that stores the content without any HTML
> > tags. That way, you can search and not worry about tags and attribute
> > values getting in the way.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
> >
>
> Is this the only way? Couldn't i do it in mysql query? Seems much cleaner...
>
> Br,
> Tanel
>
>
>
You could try and do it in MySQL with a regex to filter out the HTML
tags. The regex would be real complex though, and prone to failure if
the HTML wasn't perfectly formed. And it would be a *lot* slower than
searching a plain text field. I think it's far cleaner to use a second
field like that.
Thanks,
Ash
http://www.ashleysheridan.co.uk