WordPress.org

Make WordPress Core

Changeset 17621


Ignore:
Timestamp:
04/07/2011 03:46:57 PM (9 years ago)
Author:
markjaquith
Message:

Add mb_substr() back to compat.php (it is non-default). see #16918. props joostdevalk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/compat.php

    r17620 r17621  
    1313    }
    1414}
     15
     16if ( !function_exists('mb_substr') ):
     17    function mb_substr( $str, $start, $length=null, $encoding=null ) {
     18        return _mb_substr($str, $start, $length, $encoding);
     19    }
     20endif;
     21
     22function _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
     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);
     28    }
     29    // use the regex unicode support to separate the UTF-8 characters into an array
     30    preg_match_all( '/./us', $str, $match );
     31    $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
     32    return implode( '', $chars );
     33}
Note: See TracChangeset for help on using the changeset viewer.