views:

680

answers:

3

The best that I have been able to come up with is:

strlen(preg_replace('/^([\\*]*)\s(.+)/',"$1",$line));
^^That seems to give the length of the string.^^

edit: I think that I should clarify that the character that I am trying to find is '*'

+2  A: 

This is a little wonky but it might work--it counts the number of times the first character is repeated:

strlen($line) - strlen(ltrim($line, $line[0]));

If you just want to remove all the stars from beginning, then this is a little easier

strlen($line) - strlen(ltrim($line, '*'));
Michael Haren
+2  A: 

preg_match allows an output parameter which is filled with the matches, thus you can simply take the strlen of the match for the pattern /^**/:

$matches = array();
preg_match("/^\**/", $string, $matches);
$result =  strlen($matches[0]) ;

...

"***Hello world!*" -> 3
"Hello world!" -> 0
Aaron Maenpaa
A: 

If i want to count which character is repeated twice, because i am not entering the word and the word is being entered by user and i want to tell the user that which character he pressed twice. than what to do. Give me satisfied answer. If you can...