| | 80 | if ( ! function_exists('mb_strcut') ): |
|---|
| | 81 | function mb_strcut( $str, $start, $length=null, $encoding=null ) { |
|---|
| | 82 | return _mb_strcut($str, $start, $length, $encoding); |
|---|
| | 83 | } |
|---|
| | 84 | endif; |
|---|
| | 85 | |
|---|
| | 86 | function _mb_strcut( $str, $start, $length=null, $encoding=null ) { |
|---|
| | 87 | // the solution below, works only for utf-8, so in case of a different |
|---|
| | 88 | // charset, just use built-in substr |
|---|
| | 89 | $charset = get_option( 'blog_charset' ); |
|---|
| | 90 | if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) { |
|---|
| | 91 | return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length); |
|---|
| | 92 | } |
|---|
| | 93 | // use the regex unicode support to separate the UTF-8 characters into an array |
|---|
| | 94 | preg_match_all( '/./us', $str, $match ); |
|---|
| | 95 | $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length ); |
|---|
| | 96 | return implode( '', $chars ); |
|---|
| | 97 | } |
|---|
| | 98 | |
|---|