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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Apr 25 09:01:29 2024 UTC