<?php $str = "This is a beautiful world!"; //substr_count()计算指定字符串中子字符串出现的次数。 //$newstr = substr_count($str,"is"); //is出现了两次,所以输出结果显示2 //echo $newstr; //substr_replace() 函数把字符串的一部分替换为另一个字符串 replace(替换); echo substr_replace($str,"was",5,2); //($str,"was",5,2) 表示在 $str里面替换"was",从第5个字符串开始,替换2个字符; ?>
<?php
// 字符串组成数组
$str = "zhangsan,lisi,wangwu"; //用逗号分隔的字符串
$newstr = explode(",",$str); //用逗号分隔的变成数组
print_r($newstr) ; //输出结果 Array ( [0] => zhangsan [1] => lisi [2] => wangwu )
$str2 = implode(",",$newstr); //这个跟上面的操作相反,把上面的
//得出的数组,用","号隔开 转成字符串
echo $str2; //输出结果 zhangsan,lisi,wangwu
?>
原文链接:https://www.qiquanji.com/post/7281.html
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
微信扫码关注
更新实时通知
