Jump to content

Ignore Punctuation


The Little Guy

Recommended Posts

in a match against search, is it possible to ignore punctuation?

 

for example, I have McDonald's in the table, and if I do a search like this mcdonalds, I get no results. If I search for mcdonald I will get results. So how can I ignore punctuation marks, so no matter how I search mcdonald, mcdonalds, McDonald's I will get similar results?

Link to comment
Share on other sites

You can't do that.  The punctuation isn't the problem, the problem is that you are searching for either '%value%' or 'value%'. either way, your search string doesn't match the value in the table.  It's nothing to do with punctuation.  e.g. if you had 'Taco Bell' in your database and searched for 'Taco Belle' you would get nothing, nor would you get anything if you searched for ' Tacco Bell' or 'Taco Sell'.  This is because the characters you are submiting in the string do not match the characters that are in the same postion in the strings that are already stored.

Link to comment
Share on other sites

Can you use a regular expression in php to first remove any punctuation??

$string = preg_replace('/[^a-zA-Z0-9 ]/','',$string);

no, I need to keep the format of the text in the database

 

I'm curious, how would it affect the format in the database? Wouldn't it just switch mcdonald's to mcdonalds in the string to use in the match?

Link to comment
Share on other sites

None of this matters.  You need to store a clean version of your strings, depending on how you're searching.  Substring matches depend on the content, same with the definition of "alphanumeric', the list goes on.  Without true full-text searching (i.e. stemming, etc.), this is all smoke and mirrors.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.