sql_regcase
(PHP 4, PHP 5)
sql_regcase — Make regular expression for case insensitive match
Описание
Creates a regular expression for a case insensitive match.
Список параметров
- string
-
The input string.
Возвращаемые значения
Returns a valid regular expression which will match string , ignoring case. This expression is string with each alphabetic character converted to a bracket expression; this bracket expression contains that character's uppercase and lowercase form. Other characters remain unchanged.
Примеры
Пример #1 sql_regcase() example
<?php
echo sql_regcase("Foo - bar.");
?>
Результат выполнения данного примера:
[Ff][Oo][Oo] - [Bb][Aa][Rr].
This can be used to achieve case insensitive pattern matching in products which support only case sensitive regular expressions.
Коментарии
if you set right locale:
setlocale(LC_CTYPE,"ru_RU.KOI8-R");
print sql_regcase("Цffnung");
will output:
"[Цц][Ff][Ff][Nn][Uu][Nn][Gg]"
This function naivley replaces the letters in your expression.
if your expression uses [] already using this will probably break it
function php7_regcase($str)
{
if (empty($str))
return '';
$chars = str_split($str);
foreach ($chars as $char) {
if (preg_match("/[A-Za-z]/", $char)) {
$str_upper = mb_strtoupper($char, 'UTF-8');
$str_lower = mb_strtolower($char, 'UTF-8');
$resp[] = "[{$str_upper}{$str_lower}]";
} else {
$resp[] = $char;
}
}
return implode('', $resp);
}