16 | | if ( !function_exists('mb_substr') ): |
17 | | function mb_substr( $str, $start, $length=null, $encoding=null ) { |
18 | | return _mb_substr($str, $start, $length, $encoding); |
| 16 | if ( ! function_exists( 'mb_substr' ) ) : |
| 17 | function mb_substr( $str, $start, $length = null, $encoding = null ) { |
| 18 | return _mb_substr( $str, $start, $length, $encoding ); |
22 | | function _mb_substr( $str, $start, $length=null, $encoding=null ) { |
23 | | // the solution below, works only for utf-8, so in case of a different |
24 | | // charset, just use built-in substr |
| 22 | function _mb_substr( $str, $start, $length = null, $encoding = null ) { |
| 23 | // The solution below works only for UTF-8, |
| 24 | // so in case of a different charset just use built-in substr() |
26 | | if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) { |
27 | | return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length); |
| 26 | if ( ! in_array( $charset, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) { |
| 27 | return is_null( $length ) ? substr( $str, $start ) : substr( $str, $start, $length ); |
| 35 | if ( ! function_exists( 'mb_strlen' ) ) : |
| 36 | function mb_strlen( $str, $encoding = null ) { |
| 37 | return _mb_strlen( $str, $encoding ); |
| 38 | } |
| 39 | endif; |
| 40 | |
| 41 | function _mb_strlen( $str, $encoding = null ) { |
| 42 | // The solution below works only for UTF-8, |
| 43 | // so in case of a different charset just use built-in substr() |
| 44 | $charset = get_option( 'blog_charset' ); |
| 45 | if ( ! in_array( $charset, array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) ) ) { |
| 46 | return strlen( $str ); |
| 47 | } |
| 48 | // Use the regex unicode support to separate the UTF-8 characters into an array |
| 49 | preg_match_all( '/./us', $str, $match ); |
| 50 | return count( $match[0] ); |
| 51 | } |
| 52 | |