Re[2]: [PHP] Counting number of characters without spaces between them?

From: Date: Fri, 23 Apr 2004 14:56:59 +0000
Subject: Re[2]: [PHP] Counting number of characters without spaces between them?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-184397@lists.php.net to get a copy of this message
Hi, Saturday, April 24, 2004, 12:42:57 AM, you wrote: TR> Hi, TR> Friday, April 23, 2004, 11:50:56 PM, you wrote: TR> You could try something like this TR> $string = "hello world!!!!!!!!!!!!!!!!! how arrrrrrrrrrrrrrre you today?????!!"; TR> if(preg_match_all('/(\w)\1{4,}|(\W)\2{4,}/',$string,$match)){ TR> echo "too many repeated characters<br>"; TR> print_r($match); TR> } TR> That will catch everything, except numbers, that is repeated 4 or more TR> times. With preg_split() you can do a bit of correction too: $string = "hello world!!!!!!!!!!!!!!!!! how arrrrrrrrrrrrrrre you today?????!!"; if(preg_match_all('/(\w)\1{4,}|(\W)\2{4,}/',$string,$match)){ echo "too many repeated characters<br>"; print_r($match); } $split = preg_split('/(\w)\1{4,}|(\W)\2{4,}/',$string); print_r($split); $out = ''; foreach($split as $key=>$val){ $out .= $val; if(!empty($match[1][$key])) $out .= $match[1][$key]; elseif(!empty($match[2][$key])) $out .= $match[2][$key]; } echo $out.'<br>'; The tricks you learn with this PHP :-) -- regards, Tom

« previous php.general (#184397) next »