/**
  * Returns the character length of a string.
  *
  * @param string $str A multibyte or singlebyte string.
  *
  * @return integer  The string length.
  */
 function _strlen($str)
 {
     static $mbstring;
     // Strip ANSI color codes if requested.
     if ($this->_ansiColor) {
         $str = Console_Color::strip($str);
     }
     // Cache expensive function_exists() calls.
     if (!isset($mbstring)) {
         $mbstring = function_exists('mb_strwidth');
     }
     if ($mbstring) {
         return mb_strwidth($str, $this->_charset);
     }
     return strlen($str);
 }
Exemple #2
0
 /**
  * Returns the character length of a string.
  *
  * @param string $str A multibyte or singlebyte string.
  *
  * @return integer  The string length.
  */
 function _strlen($str)
 {
     static $mbstring, $utf8;
     // Strip ANSI color codes if requested.
     if ($this->_ansiColor) {
         include_once 'Console/Color.php';
         $str = Console_Color::strip($str);
     }
     // Cache expensive function_exists() calls.
     if (!isset($mbstring)) {
         $mbstring = function_exists('mb_strlen');
     }
     if (!isset($utf8)) {
         $utf8 = function_exists('utf8_decode');
     }
     if ($utf8 && ($this->_charset == strtolower('utf-8') || $this->_charset == strtolower('utf8'))) {
         return strlen(utf8_decode($str));
     }
     if ($mbstring) {
         return mb_strlen($str, $this->_charset);
     }
     return strlen($str);
 }