PHP/MySQL - include plurals but exclude singulars

前端 未结 3 1529
挽巷
挽巷 2021-01-21 11:47

I am building a site with a requirement to include plural words but exclude singlular words, as well as include longer phrases but exclude shorter phrases found within it.

3条回答
  •  爱一瞬间的悲伤
    2021-01-21 12:39

    With MySQL you can use REGEXP instead of like which would give you better control over your query...

    SELECT * FROM table WHERE field REGEXP '\s+read\s+'
    

    That would at least enforce word boundaries around your query and gives you much better control over your matching - with the downside of a performance hit though.

提交回复
热议问题