时间:2021-07-01 10:21:17 帮助过:8人阅读
function replace_once($replace,$str,$targetstr)/$replace为要替换的字串,$targetstr为替换字串,$str为原字串
{
$tempstr = $str;
for (;;)
{
$tempindex = strrpos($tempstr,$replace);
if($tempindex!=false)
{
$tempstr = substr($str,0,$tempindex);
}
else break;
}
$replaceindex = strlen($tempstr);
//echo$replaceindex;
//echo $replaceindex."hao";
$str = substr($str,0,$replaceindex).$targetstr.substr($str,$replaceindex+strlen($replace));
return $str;
}