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 '*'
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 '*'
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, '*'));
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