2012-11-04 40 views

回答

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 
+0

如果你想保留一個問號,用'「?」'而不是'「」'替換模式。 –

+0

它工作正常:) – Spacedust