删除指定字符串之后或之前所有字符的函数
<?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."]+[\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; } //使用方法例: http://www.ijingxuan.com/ $mub = "情无"; $zhi = "随风舞动,心情无限!"; echo paichu($mub,$zhi,"l"); //输出: 随风舞动,心 echo paichu($mub,$zhi,"r"); //输出: 无! echo paichu($mub,$zhi,""); //输出: 随风舞动,心限 ?>