source: trunk/web/punbb/include/utf8/strcspn.php @ 6

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

mise a jour du trunk

File size: 809 bytes
Line 
1<?php
2
3/**
4* @version $Id: strcspn.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 strcspn
11* Find length of initial segment not 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/strcspn
16* @see utf8_strlen
17* @package utf8
18* @subpackage strings
19*/
20function utf8_strcspn($str, $mask, $start=null, $length=null)
21{
22        if (empty($mask) || strlen($mask) == 0)
23                return null;
24
25        $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}', $mask);
26
27        if ($start !== null || $length !== null)
28                $str = utf8_substr($str, $start, $length);
29
30        preg_match('/^[^'.$mask.']+/u', $str, $matches);
31
32        if (isset($matches[0]))
33                return utf8_strlen($matches[0]);
34
35        return 0;
36}
Note: See TracBrowser for help on using the repository browser.