经测试代码如下:
/**
* 函数一 作用 排除 l代表排除指定字符串左边的,r代表排除指定字符串右边的
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
function paichu($mub,$zhi,$a){
if(!$mub){
return "被替换的字符串不存在";
}
$mub = mb_convert_encoding($mub,'GB2312','UTF-8');
$zhi = mb_convert_encoding($zhi,'UTF-8');
if($a==""){
$last = str_replace($mub,"",$zhi);
}elseif($a=="r"){
$last = preg_replace("/[".$mub."]+[\d\D\w\W\s\S]*/",$zhi);
}elseif($a=="l"){
$last = preg_replace("/[\d\D\w\W\s\S]*[".$mub."]+/",$zhi);
}
$last = mb_convert_encoding($last,'UTF-8','GB2312');
return $last;
}
$mub = "情无";
$zhi = "随风舞动,心情无限!";
echo paichu($mub,"l"); //输出: 随风舞动,心
echo paichu($mub,"r"); //输出: 无!
echo paichu($mub,""); //输出: 随风舞动,心限
原文链接:https://www.f2er.com/php/529052.html