php str_replace 字符串替换

我们在这里使用 str_replace 来替换一串字符串中的字符,例如如下代码:

<?php
$str='Hello world!';
$str1=str_replace("world","Terry",$str);
echo $str1;

str的值为Hello world!,我们在str_replace后面第一个参数是world意思是str字符串中的world要替换成什么字符串。然后我们就在第二个 参数 内填写要替换成的字符串即可。那么,我们输出的是:
Hello Terry!

猜你喜欢

转载自blog.csdn.net/a757291228/article/details/60966286
今日推荐