【问题标题】:How to find results containing either uppercase or lowercase non-latin phrase? (PHP, MySQL) [duplicate]如何查找包含大写或小写非拉丁短语的结果? (PHP,MySQL)[重复]
【发布时间】:2019-08-06 06:49:36
【问题描述】:

我遇到了一些关于非拉丁字符的问题。

查询:

SELECT * FROM table WHERE name LIKE '%{$phrase}%'

PHP:

$phrase = $_POST['phrase'];
//$phrase = strtolower/strtoupper($_POST['phrase']) made no differece

演示数据库:

Asomething (in the db stored as Asomething)
asomething (in the db stored as asomething)
Äsomething (in the db stored as Äsomething)
äsomething (in the db stored as äsomething) 

无论我输入 a 还是 A,我都会得到我想要的 - 两个结果,但是... 如果我输入 Ä,我会得到 只有一个结果包含大写。我怎样才能同时获得它们?

已编辑:我使用排序规则 utf8_general_ci

【问题讨论】:

标签: php mysql character sql-like


【解决方案1】:

始终将您的搜索查询小写。

SELECT * FROM table WHERE LOWER( name ) LIKE '%{$phrase}%'

https://stackoverflow.com/a/2876802/2693543

【讨论】:

  • 当然还要使用准备好的语句。
  • 是的,当然... ;)
  • 这个对我没有任何帮助。我知道有准备,但这里不是这样。不过谢谢你的关心。
【解决方案2】:

尝试使用mb_strtolower($phrase , 'UTF-8');

【讨论】:

  • 尽管我之前发表了评论,但这不应该是解决方案。
  • @mickmackusa 嗯.. 可以为此编写特定的函数
  • 如果搜索不敏感,似乎没有必要重新大小写。
猜你喜欢
  • 1970-01-01
  • 2014-07-06
  • 2011-10-02
  • 2013-08-22
  • 2021-06-03
  • 2012-02-11
  • 1970-01-01
  • 2013-01-16
  • 2016-08-18
相关资源
最近更新 更多