+
80
-

php 字符串查找与替换如何不区分大小写?

php

php 字符串查找与替换如何不区分大小写?


网友回复

+
0
-

str_ireplace()可以实现,他主要是查找与替换字符串中的指定内容,不区分大小写,他与str_replace的区别就是str_replace区分大小写,下面我们看语法:

语法:str_ireplace(find,replace,string,count) 参数: find:必需。规定要查找的值。 replace:必需。规定替换 find 中的值的值。 string:必需。规定被搜索的字符串。 count:可选。一个变量,对替换数进行计数。

示例代码:

<?php
$str = 'hello,BfW.Com';
echo str_ireplace('bfw.COM', 'world', $str);
?>

同样不区分大小写来替换数组元素的代码如下:

<?php
$array = array('bfw.wiki', 'blog', 'code', 'school', 'moban', "BFW.wiki");
$arr = str_ireplace("bfw.wiki", "world", $array, $i);
print_r($arr);
echo '共替换了'.$i.'次';
?>

我知道答案,我要回答