[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-includes/ -> compat.php (source)

   1  <?php
   2  /**
   3   * WordPress implementation for PHP functions either missing from older PHP versions or not included by default.
   4   *
   5   * @package PHP
   6   * @access private
   7   */
   8  
   9  // If gettext isn't available
  10  if ( !function_exists('_') ) {
  11      function _($string) {
  12          return $string;
  13      }
  14  }
  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);
  19      }
  20  endif;
  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 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  }


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting