php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66637 Please don't remove sql_regcase
Submitted: 2014-02-03 20:05 UTC Modified: 2014-02-04 09:12 UTC
From: marco at thenetworksolution dot it Assigned:
Status: Wont fix Package: *Regular Expressions
PHP Version: 5.4.24 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: marco at thenetworksolution dot it
New email:
PHP Version: OS:

 

 [2014-02-03 20:05 UTC] marco at thenetworksolution dot it
Description:
------------
Just noticed that I've just reimplemented in my project the sql_regcase.
Please don't remove, it is useful in implementing accent insensitive searches on top of MySQL.

---
From manual page: http://www.php.net/function.sql-regcase
---



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-03 20:17 UTC] requinix@php.net
-Status: Open +Status: Wont fix
 [2014-02-03 20:17 UTC] requinix@php.net
It has been deprecated because there are better alternatives:
* In PHP: using the PCRE functions and the /i flag for case-insensitivity.
* In SQL: depends on the DBMS but many problems can be solved by using the right charset and collation. In MySQL you'd use, for example, utf8_general_ci on the column. [1]

[1] http://dev.mysql.com/doc/refman/5.6/en/charset-general.html
 [2014-02-04 07:23 UTC] marco at thenetworksolution dot it
Hi. There is just one use case in which nor PCRE nor charset and collation are useful. This case is solvable with sql_regcase.

Please consider this use case:
"perform a case insensitive and accent insensitive word search (must match only entire words)"

- utf8_general_ci allows you to make an equality (WHERE field = value) case and accent insensitive search but it doesn't allow you to specify an entire word match (word boundaries markers not recognized)
- LIKE allows you case and accent insensitive search but you have to manually specify all combinations of possible word boundaries charactes (word boundaries markers not recognized)
- word boundaries [[:<:]] and [[:>:]] are supported in REGEXP, who is a single byte functions so don't perform accent insensitive search.

The solution is to use REGEXP with word boundaries and the word modified in the way sql_regcase does.

Used on http://www.genovaperte.it
 [2014-02-04 09:12 UTC] requinix@php.net
sql_regcase() has a very limited usage as far as I can see: matching single-byte characters when you need a REGEXP in MySQL. Because (1) it won't work correctly with multibyte characters, especially with more than one, (2) LIKE handles the general don't-need-full-regular-expressions use case, and (3) like I said before the PCRE functions are better for use in just PHP.

If you really need the functionality then there is a straightforward userland solution: the one started by @irker on the manual page. Could use some touching up though, like using "(up|low)" instead of the flawed "[uplow]". (Searching around for "mb_sql_regcase" seems to turn up a number of results.)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC