0

我想删除四个或更多问号。

我现在正在使用这个:

preg_replace( '{\\?+}', '', $text );

但这确实删除了所有问号。

4

1 回答 1

1
// Use {4,} to indicate 4 or more of the preceding thing
$pattern = '~\?{4,}~';

$str = "I have 3??? and that isn't enough";
$str2 = "I have 5????? and that is enough";

// Won't replace only 3 ?
echo preg_replace($pattern, '', $str);
// I have 3??? and that isn't enough

// Will replace 5 ?
echo preg_replace($pattern, '', $str2);
// I have 5 and that is enough
于 2012-11-04T20:02:37.407 回答