PHP Velho Oeste 2024

sql_regcase

(PHP 4, PHP 5)

sql_regcase产生用于不区分大小的匹配的正则表达式

说明

sql_regcase ( string $string ) : string

产生用于不区分大小的匹配的正则表达式

Warning

自 PHP 5.3.0 起,已经废弃此函数。强烈建议不要应用此函数。

参数

string

输入的字符。

返回值

返回与 string 相匹配的正则表达式,不论大小写字母。返回的表达式是将 string 中的每个字母字符转换为方括号表达式,该方括号表达式包含了该字母的大小写形式。其它字符保留不变。

范例

Example #1 sql_regcase() 例子

<?php
echo sql_regcase("Foo - bar.");
?>

以上例程会输出:

[Ff][Oo][Oo] - [Bb][Aa][Rr].

可以用于在仅支持区分大小写正则表达式的产品中完成不区分大小写的模式匹配。

注释

add a note add a note

User Contributed Notes 3 notes

up
0
fernandovaller at gmail dot com
4 years ago
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);
}
up
0
edge at gts dot smtn dot stavropol dot ru
20 years ago
if you set right locale:

setlocale(LC_CTYPE,"ru_RU.KOI8-R");

print sql_regcase("Цffnung");

will output:
"[Цц][Ff][Ff][Nn][Uu][Nn][Gg]"
up
-2
phpcomment at revmaps dot no-ip dot biz
10 years ago
This function naivley replaces the letters in your expression.
if your expression uses [] already using this will probably break it
To Top