Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
strspn.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3 * @version $Id$
4 * @package utf8
5 * @subpackage strings
6 */
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 */
19 function utf8_strspn($str, $mask, $start = NULL, $length = NULL) {
20 
21  $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\${1}',$mask);
22 
23  // Fix for $start but no $length argument.
24  if ($start !== null && $length === null) {
25  $length = utf8_strlen($str);
26  }
27 
28  if ( $start !== NULL || $length !== NULL ) {
29  $str = utf8_substr($str, $start, $length);
30  }
31 
32  preg_match('/^['.$mask.']+/u',$str, $matches);
33 
34  if ( isset($matches[0]) ) {
35  return utf8_strlen($matches[0]);
36  }
37 
38  return 0;
39 
40 }
41