1 <?php
2 3 4
5
6
7 8 9 10 11 12 13 14 15
16 function utf8_strspn($str, $mask, $start = NULL, $length = NULL) {
17
18 $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$mask);
19
20
21 if ($start !== null && $length === null) {
22 $length = utf8_strlen($str);
23 }
24
25 if ( $start !== NULL || $length !== NULL ) {
26 $str = utf8_substr($str, $start, $length);
27 }
28
29 preg_match('/^['.$mask.']+/u',$str, $matches);
30
31 if ( isset($matches[0]) ) {
32 return utf8_strlen($matches[0]);
33 }
34
35 return 0;
36
37 }
38
39