[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/phputf8/ -> strcspn.php (source)

   1  <?php
   2  /**
   3  * @version $Id: strcspn.php 10381 2008-06-01 03:35:53Z pasamio $
   4  * @package utf8
   5  * @subpackage strings
   6  */
   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  */
  20  function utf8_strcspn($str, $mask, $start = NULL, $length = NULL) {
  21  
  22      if ( empty($mask) || strlen($mask) == 0 ) {
  23          return NULL;
  24      }
  25  
  26      $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\$1}',$mask);
  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  


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1