Changeset 32114 for trunk/src/wp-includes/compat.php
- Timestamp:
- 04/11/2015 11:13:01 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/compat.php
r31188 r32114 14 14 } 15 15 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 ); 19 19 } 20 20 endif; 21 21 22 function _mb_substr( $str, $start, $length =null, $encoding=null ) {23 // the solution below, works only for utf-8, so in case of a different24 // charset, just use built-in substr22 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() 25 25 $charset = get_option( 'blog_charset' ); 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 ); 28 28 } 29 // use the regex unicode support to separate the UTF-8 characters into an array29 // Use the regex unicode support to separate the UTF-8 characters into an array 30 30 preg_match_all( '/./us', $str, $match ); 31 $chars = is_null( $length ) ? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );31 $chars = is_null( $length ) ? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length ); 32 32 return implode( '', $chars ); 33 } 34 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] ); 33 51 } 34 52
Note: See TracChangeset
for help on using the changeset viewer.