1 <?php
2 3 4
5
6
7 8 9 10 11 12 13 14 15 16
17 function utf8_strcspn($str, $mask, $start = NULL, $length = NULL) {
18
19 if ( empty($mask) || strlen($mask) == 0 ) {
20 return NULL;
21 }
22
23 $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$mask);
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