[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/string/src/phputf8/ -> strcspn.php (source)

   1  <?php
   2  /**
   3  * @package utf8
   4  */
   5  
   6  //---------------------------------------------------------------
   7  /**
   8  * UTF-8 aware alternative to strcspn
   9  * Find length of initial segment not matching mask
  10  * Note: requires utf8_strlen and utf8_substr (if start, length are used)
  11  * @param string
  12  * @return int
  13  * @see http://www.php.net/strcspn
  14  * @see utf8_strlen
  15  * @package utf8
  16  */
  17  function utf8_strcspn($str, $mask, $start = NULL, $length = NULL) {
  18  
  19      if ( empty($mask) || strlen($mask) == 0 ) {
  20          return NULL;
  21      }
  22  
  23      $mask = preg_replace('!([\\\\\\-\\]\\[/^])!','\\\$1}',$mask);
  24  
  25      if ( $start !== NULL || $length !== NULL ) {
  26          $str = utf8_substr($str, $start, $length);
  27      }
  28  
  29      preg_match('/^[^'.$mask.']+/u',$str, $matches);
  30  
  31      if ( isset($matches[0]) ) {
  32          return utf8_strlen($matches[0]);
  33      }
  34  
  35      return 0;
  36  
  37  }
  38  


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer