3 * @version $Id: strcspn.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
8 //---------------------------------------------------------------
10 * UTF-8 aware alternative to strcspn
11 * Find length of initial segment not matching mask
12 * Note: requires utf8_strlen and utf8_substr (if start, length are used)
15 * @see http://www.php.net/strcspn
20 function utf8_strcspn($str, $mask, $start = NULL, $length = NULL) {
22 if ( empty($mask) || strlen($mask) == 0 ) {
26 $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$mask);
28 if ( $start !== NULL || $length !== NULL ) {
29 $str = utf8_substr($str, $start, $length);
32 preg_match('/^[^'.$mask.']+/u',$str, $matches);
34 if ( isset($matches[0]) ) {
35 return utf8_strlen($matches[0]);