Search a text with single quote

北慕城南 提交于 2019-12-25 03:15:01

问题


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


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/3966233/search-a-text-with-single-quote

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!