source: trunk/web/punbb/include/utf8/strspn.php @ 10

Last change on this file since 10 was 6, checked in by dj3c1t, 13 years ago

mise a jour du trunk

File size: 725 bytes
Line 
1<?php
2
3/**
4* @version $Id: strspn.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
5* @package utf8
6* @subpackage strings
7*/
8
9/**
10* UTF-8 aware alternative to strspn
11* Find length of initial segment matching mask
12* Note: requires utf8_strlen and utf8_substr (if start, length are used)
13* @param string
14* @return int
15* @see http://www.php.net/strspn
16* @package utf8
17* @subpackage strings
18*/
19function utf8_strspn($str, $mask, $start=null, $length=null)
20{
21        $mask = preg_replace('!([\\\\\\-\\]\\[/^])!', '\\\${1}', $mask);
22
23        if ($start !== null || $length !== null)
24                $str = utf8_substr($str, $start, $length);
25
26        preg_match('/^['.$mask.']+/u', $str, $matches);
27
28        if (isset($matches[0]))
29                return utf8_strlen($matches[0]);
30
31        return 0;
32}
Note: See TracBrowser for help on using the repository browser.