我想用 php 做一些简单的替换。
对于第一次出现的 "xampp" ,将其替换为 "xp"。
对于“xampp”的第二次/最后一次出现,将其替换为“rrrr”
$test = "http://localhost/xampp/splash/xampp/.php";
echo $test."<br>";
$count = 0;
$test = str_replace ("xampp","xp",$test,$count);
echo $test."<br>";
$count = 1;
$test = str_replace ("xampp","rrrr",$test,$count);
echo $test;
查看文档后,我发现 $count 是只返回字符串匹配的地方。它不会用指定的特定匹配项替换字符串。那么有什么方法可以完成任务吗?