-if ( !function_exists('mb_substr') ):
- function mb_substr( $str, $start, $length=null, $encoding=null ) {
- return _mb_substr($str, $start, $length, $encoding);
- }
-endif;
-
-function _mb_substr( $str, $start, $length=null, $encoding=null ) {
- // the solution below, works only for utf-8, so in case of a different
- // charset, just use built-in substr
- $charset = get_option( 'blog_charset' );
- if ( !in_array( $charset, array('utf8', 'utf-8', 'UTF8', 'UTF-8') ) ) {
- return is_null( $length )? substr( $str, $start ) : substr( $str, $start, $length);
- }
- // use the regex unicode support to separate the UTF-8 characters into an array
- preg_match_all( '/./us', $str, $match );
- $chars = is_null( $length )? array_slice( $match[0], $start ) : array_slice( $match[0], $start, $length );
- return implode( '', $chars );
-}
-
-if ( !function_exists( 'htmlspecialchars_decode' ) ) {
- // Added in PHP 5.1.0
- // Error checks from PEAR::PHP_Compat
- function htmlspecialchars_decode( $string, $quote_style = ENT_COMPAT )
- {
- if ( !is_scalar( $string ) ) {
- trigger_error( 'htmlspecialchars_decode() expects parameter 1 to be string, ' . gettype( $string ) . ' given', E_USER_WARNING );
- return;
- }
-
- if ( !is_int( $quote_style ) && $quote_style !== null ) {
- trigger_error( 'htmlspecialchars_decode() expects parameter 2 to be integer, ' . gettype( $quote_style ) . ' given', E_USER_WARNING );
- return;
- }
-
- return wp_specialchars_decode( $string, $quote_style );
- }
-}
-
-// For PHP < 5.2.0