0

There is a CKEditor field on our website which saves it's HTML to a text field in a MySQL database.

What I'm wondering is, if there is a function (regex for example?) that could strip out HTML tags when doing a LIKE match,

e.g. so that searching for:

like '%this is a test%'

would find

'this<strong>is</strong>a test

I get the feeling that it won't be practical/possible, but worth an ask!

JohnK
  • 21
  • 4
  • 1
    [Friends don't let friends parse HTML with regular expressions.](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Ether Sep 27 '10 at 19:04

1 Answers1

1

I think your better bet would be to strip all of the HTML and store a plain-text version of that in your database table. As Ether noted though, don't use REGEX to remove the HTML when you do it.

BBonifield
  • 4,983
  • 19
  • 36
  • Agreed. If you're going to be doing a lot of those kinds of searches, it's worth the extra space in your DB. – Michael Mior Sep 27 '10 at 20:19
  • 2
    Thanks for the comments, unfortunately I can't add a field to the database, however I got around the problem by spliting each word of the search phrase and doing like '%firstword%' and like '%secondword%' etc etc. Not ideal in every scenario granted, but the client is happy with this solution, for now at least! – JohnK Sep 28 '10 at 19:07