PHP中的str_replace()函数
str_replace()函数用于将一个字符串替换为另一个字符串。
注 -该功能区分大小写。
语法
str_replace(find, replace, str, count)
参数
find-要搜索的值
replace-我们要替换$find的字符串
str-要搜索的字符串
count-更换数量
返回
str_replace()函数返回具有替换值的字符串或数组。
示例
以下是一个例子-
<?php
$str = "I am Amit";
$res = str_replace("Amit", "David", $str);
echo $res;
?>输出结果
I am David
示例
以下是一个例子-
<?php
$myArr = array("one","two","three");
print_r(str_replace("three","four",$myArr,$c));
echo "<br>" . "Number of Replacements = $c";
?>输出结果
Array ( [0] => one [1] => two [2] => four ) <br> Number of Replacements = 1
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短