//使用方法例:
$mub = "情无";
$zhi = "随风舞动,心情无限!";
echo paichu($mub,$zhi,"l"); //输出: 随风舞动,心
echo paichu($mub,$zhi,"r"); //输出: 无!
echo paichu($mub,$zhi,""); //输出: 随风舞动,心限
<?php /*函数一 作用 排除 l代表排除指定字符串左边的,r代表排除指定字符串右边的*/ function paichu($mub,$zhi,$a){ if(!$mub){ return "被替换的字符串不存在"; } $mub = mb_convert_encoding($mub,'GB2312','UTF-8'); $zhi = mb_convert_encoding($zhi,'GB2312','UTF-8'); if($a==""){ $last = str_replace($mub,"",$zhi); }elseif($a=="r"){ $last = preg_replace("/[".$mub."]+[dDwWsS]*/","",$zhi); }elseif($a=="l"){ $last = preg_replace("/[dDwWsS]*[".$mub."]+/","",$zhi); } $last = mb_convert_encoding($last,'UTF-8','GB2312'); return $last; } //使用方法例: $mub = "情无"; $zhi = "随风舞动,心情无限!"; echo paichu($mub,$zhi,"l"); //输出: 随风舞动,心 echo paichu($mub,$zhi,"r"); //输出: 无! echo paichu($mub,$zhi,""); //输出: 随风舞动,心限 ?>
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群