【php开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了php开源代码-replacestr.php的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
<html>
<head>
<title>字符串函数应用</title>
</head>
<body>
<h2>字符串替换函数的应用</h2>
<?php
echo "<b>str_replace()函数:</b><br>";
$str="he is a strong and pretty dog.";
echo "原字符串是:".$str."<br>";
echo "str_replace()函数:";
echo str_replace("strong","small",$str)."<br>";
echo "字符串被替换次数:";
str_replace("t", "r", $str, $count);
echo $count."<br>";
echo "当字符串为数组时:";
$colors=array("red","yellow","white","black");
$color1=array("red","yellow");
print_r(str_replace($color1,"green",$colors));
echo "<br>";
echo "<b>substr_replace()函数:</b><br>";
$str1="she is a good child.";
echo substr_replace($str1,"bad",0,13)."<br>";
echo substr_replace($str1,"woman",-6,-1)."<br>";
echo "<b>str_ireplace()函数:</b><br>";
$str2="They arE all my friEnds.";
echo str_replace("e","a",$str2)."<br>";
echo str_ireplace("e","a",$str2)."<br>";
?>
</body>
</html>