选择语言 :

 Core_UTF8::strspn

Finds the length of the initial segment matching mask. This is a UTF8-aware version of strspn.

$found = UTF8::strspn($str, $mask);

integer Core_UTF8::strspn( string $str , string $mask [, integer $offset = null , integer $length = null ] )
author
Harry Fuecks hfuecks@gmail.com

参数列表

参数 类型 描述 默认值
$str string Input string
$mask string Mask for search
$offset integer Start position of the string to examine null
$length integer Length of the string to examine null
返回值
  • integer length of the initial segment that contains characters in the mask
File: ./core/classes/utf8.class.php
public static function strspn($str, $mask, $offset = null, $length = null)
{
    if ( $str == '' || $mask == '' ) return 0;

    if ( UTF8::is_ascii($str) and UTF8::is_ascii($mask) ) return ($offset === null) ? strspn($str, $mask) : (($length === null) ? strspn($str, $mask, $offset) : strspn($str, $mask, $offset, $length));

    if ( $offset !== null || $length !== null )
    {
        $str = UTF8::substr($str, $offset, $length);
    }

    // Escape these characters:  - [ ] . : \ ^ /
    // The . and : are escaped to prevent possible warnings about POSIX regex elements
    $mask = preg_replace('#[-[\].:\\\\^/]#', '\\\\$0', $mask);
    preg_match('/^[^' . $mask . ']+/u', $str, $matches);

    return isset($matches[0]) ? UTF8::strlen($matches[0]) : 0;
}