PHP 中的 str_ireplace() 函数

phpprogrammingserver side programming更新于 2025/9/18 14:52:17

str_ireplace() 函数用于将字符替换为其他字符。

注意 − 该函数不区分大小写

语法

str_ireplace(find,replace,str,count)

参数

  • find − 待搜索的值

  • replace − 替换 find 中值的值

  • str − 待搜索的字符串

  • count −替换次数

返回

str_ireplace() 函数返回包含替换值的字符串或数组。

下面是一个例子 −

示例

<?php
$str = "I am Amit";
$res = str_ireplace("Amit", "David", $str);
echo $res;
?>

以下是输出 −

输出

I am David

让我们看另一个例子 −

示例

<?php
$myArr = array("one","two","three");
print_r(str_ireplace("three","four",$myArr,$c));
echo "<br>" . "Number of Replacements = $c";
?>

以下是输出 −

输出

Array
(
   [0] => one
   [1] => two
   [2] => four
)
Number of Replacements = 1

相关文章