开发者

Search a text with single quote

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 "m开发者_如何转开发en'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


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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜