PageRenderTime 29ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/libraries/phputf8/native/strlen.php

http://kak.googlecode.com/
PHP | 35 lines | 7 code | 2 blank | 26 comment | 1 complexity | 94501dd1f99dc325434c9df787cfd876 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @version $Id: strlen.php 10381 2008-06-01 03:35:53Z pasamio $
  4. * @package utf8
  5. * @subpackage strings
  6. */
  7. /**
  8. * Define UTF8_STRLEN as required
  9. */
  10. if ( !defined('UTF8_STRLEN') ) {
  11. define('UTF8_STRLEN',TRUE);
  12. }
  13. //--------------------------------------------------------------------
  14. /**
  15. * Unicode aware replacement for strlen(). Returns the number
  16. * of characters in the string (not the number of bytes), replacing
  17. * multibyte characters with a single byte equivalent
  18. * utf8_decode() converts characters that are not in ISO-8859-1
  19. * to '?', which, for the purpose of counting, is alright - It's
  20. * much faster than iconv_strlen
  21. * Note: this function does not count bad UTF-8 bytes in the string
  22. * - these are simply ignored
  23. * @author <chernyshevsky at hotmail dot com>
  24. * @link http://www.php.net/manual/en/function.strlen.php
  25. * @link http://www.php.net/manual/en/function.utf8-decode.php
  26. * @param string UTF-8 string
  27. * @return int number of UTF-8 characters in string
  28. * @package utf8
  29. * @subpackage strings
  30. */
  31. function utf8_strlen($str){
  32. return strlen(utf8_decode($str));
  33. }