mb_eregi_replace
多字节支持的替换正则表达式,忽略大小写
适用 PHP 版本:该函数从 PHP 4.0.6 版本开始引入,支持 PHP 5.x 和 PHP 7.x,适用于启用多字节字符串扩展(mbstring)的 PHP 环境。
mb_eregi_replace 函数用于执行一个正则表达式替换操作,但与 eregi_replace 相比,它支持多字节字符编码。该函数在执行替换时,不区分大小写,适用于支持多字节字符集的字符串(如中文、日文、韩文等)。
mb_eregi_replace(string $pattern, string $replacement, string $string, int $limit = -1, int &$count = null): string
返回执行替换操作后的字符串。如果没有匹配的内容,原字符串会被直接返回。
$pattern = "apple"; $replacement = "orange"; $string = "I have an apple and another Apple."; $result = mb_eregi_replace($pattern, $replacement, $string); echo $result;
上述代码会将字符串 "I have an apple and another Apple." 中所有的 "apple"(不区分大小写)替换成 "orange"。输出结果为:"I have an orange and another orange."。