views:

65

answers:

2

For example I have a list of words: men's package, moment, immensely How can I search in mysql sample text: "men's" and return only "men's package"

I'm using this $str = str_replace("s", "%s", $str);

If I search for "men's", it will only show: men's package

but when I search for "mens" it will also show: men's package, moment, immensely

A: 

Most database back ends provide some sort of text search functionality that will take stuff like punctuation into account (postgres and MySQL both have fulltext search that can handle this, for example). If you are getting your data from a database, then I'd advise looking into what text searching functionality your back end supports.

Gordon
A: 

I don;t really understand what your string replace function is doing, but what about sql wildcards?

SELECT * FROM <table>
WHERE <field> LIKE '%men%'

this will return anything starting with men. You can put the wildcard symbol at the start, end, middle, anywhere!

If that's what you're doing in the string replace then ignore this!

iamjonesy