Skip to content

Commit

Permalink
Merge pull request #73 from wp-cli/fix-undefined-mb
Browse files Browse the repository at this point in the history
Check that `mb_detect_encoding()` exists too before using
  • Loading branch information
danielbachhuber committed Dec 3, 2014
2 parents 98db678 + 1e7b3e2 commit edead86
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/cli/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function menu( $items, $default = null, $title = 'Choose an item' ) {
* @return int Numeric value that represents the string's length
*/
function safe_strlen( $str ) {
if ( function_exists( 'mb_strlen' ) ) {
if ( function_exists( 'mb_strlen' ) && function_exists( 'mb_detect_encoding' ) ) {
$length = mb_strlen( $str, mb_detect_encoding( $str ) );
} else {
// iconv will return PHP notice if non-ascii characters are present in input string
Expand All @@ -182,7 +182,7 @@ function safe_strlen( $str ) {
* @return string Substring of string specified by start and length parameters
*/
function safe_substr( $str, $start, $length = false ) {
if ( function_exists( 'mb_substr' ) ) {
if ( function_exists( 'mb_substr' ) && function_exists( 'mb_detect_encoding' ) ) {
$substr = mb_substr( $str, $start, $length, mb_detect_encoding( $str ) );
} else {
// iconv will return PHP notice if non-ascii characters are present in input string
Expand All @@ -204,7 +204,7 @@ function safe_substr( $str, $start, $length = false ) {
function safe_str_pad( $string, $length ) {
// Hebrew vowel characters
$cleaned_string = preg_replace( '#[\x{591}-\x{5C7}]+#u', '', Colors::decolorize( $string ) );
if ( function_exists( 'mb_strwidth' ) ) {
if ( function_exists( 'mb_strwidth' ) && function_exists( 'mb_detect_encoding' ) ) {
$real_length = mb_strwidth( $cleaned_string, mb_detect_encoding( $string ) );
} else {
$real_length = safe_strlen( $cleaned_string );
Expand Down

0 comments on commit edead86

Please sign in to comment.