Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: utf8

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /phputf8/strspn.php

Documentation is available at strspn.php

  1. <?php
  2. /**
  3. * @version $Id: strspn.php,v 1.1 2006/02/25 13:50:17 harryf Exp $
  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.     if ( $start !== NULL || $length !== NULL ) {
  24.         $str = utf8_substr($str, $start, $length);
  25.     }
  26.  
  27.     preg_match('/^['.$mask.']+/u',$str, $matches);
  28.  
  29.     if ( isset($matches[0]) ) {
  30.         return utf8_strlen($matches[0]);
  31.     }
  32.  
  33.     return 0;
  34.  
  35. }

Documentation generated on Mon, 05 Mar 2007 21:27:20 +0000 by phpDocumentor 1.3.1