/**
* php将字符串中连续的某个字符替换为一个
* @param string $search
* @param string $replace
* @param string $subject
* @return string
*/
function str_replace_multiple_consecutive($search, $replace, $subject) {
return (string)preg_replace("/[" . $search . "]+/i", $replace, $subject);
}
$str = ",,,,www.####phpernote##.com,,,,我喜欢,,,,我很###喜欢#!,,,";
$str1 = str_replace_multiple_consecutive(',', ',', $str);
$str2 = str_replace_multiple_consecutive(',', ',', $str1);
$str3 = str_replace_multiple_consecutive('#', '', $str2);
echo "处理前:" . $str, '
';
//处理前:,,,,www.####phpernote##.com,,,,我喜欢,,,,我很###喜欢#!,,,
echo "处理后:" . $str1, '
';
//处理后:,,,www.####phpernote##.com,,,,我喜欢,,,我很###喜欢#!,,,
echo "处理后:" . $str2, '
';
//处理后:,www.####phpernote##.com,我喜欢,我很###喜欢#!,
echo "处理后:" . $str3, '
';
//处理后:,www.phpernote.com,我喜欢,我很喜欢!,
标签:字符,www,string,phpernote,replace,str,字符串,php,com
来源: https://www.cnblogs.com/cuteur/p/13769388.html