Yakirbu
Yakirbu

Reputation: 182

Search within Mysql with special chars

If I have a table files and it has a column title, and some of the titles are in this format:

google: and facebook
stack: overflow

Now I'm trying to add search functionality in my app, which executes a LIKE '%word%' query. But if people search google and facebook it doesn't find anything, unless they specifically search for google: and facebook. I know what LIKE does and why it doesn't give the results I'm looking for, I'm just asking if there's a way to search in mysql table and ignoring special chars like : ' - . , " etc.

Thanks.

Upvotes: 0

Views: 50

Answers (3)

smozgur
smozgur

Reputation: 1812

Use REPLACE function prior to comparison.

... REPLACE( fieldname, ':', '') LIKE %word%

Upvotes: 1

Thallius
Thallius

Reputation: 2619

You can work with regular expressions

MYSQL Manual

Upvotes: 0

faulix90
faulix90

Reputation: 180

Alternative is to replace all spaces in the search string with '%' or you explode the search string (space as separater) and connect the different parts with an OR statement.

Upvotes: 0

Related Questions