[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/joomla/string/src/phputf8/ -> utf8.php (source)

   1  <?php
   2  /**
   3  * This is the dynamic loader for the library. It checks whether you have
   4  * the mbstring extension available and includes relevant files
   5  * on that basis, falling back to the native (as in written in PHP) version
   6  * if mbstring is unavailabe.
   7  *
   8  * It's probably easiest to use this, if you don't want to understand
   9  * the dependencies involved, in conjunction with PHP versions etc. At
  10  * the same time, you might get better performance by managing loading
  11  * yourself. The smartest way to do this, bearing in mind performance,
  12  * is probably to "load on demand" - i.e. just before you use these
  13  * functions in your code, load the version you need.
  14  *
  15  * It makes sure the the following functions are available;
  16  * utf8_strlen, utf8_strpos, utf8_strrpos, utf8_substr,
  17  * utf8_strtolower, utf8_strtoupper
  18  * Other functions in the ./native directory depend on these
  19  * six functions being available
  20  * @package utf8
  21  */
  22  
  23  /**
  24  * Put the current directory in this constant
  25  */
  26  if ( !defined('UTF8') ) {
  27      define('UTF8',dirname(__FILE__));
  28  }
  29  
  30  /**
  31  * If string overloading is active, it will break many of the
  32  * native implementations. mbstring.func_overload must be set
  33  * to 0, 1 or 4 in php.ini (string overloading disabled).
  34  * Also need to check we have the correct internal mbstring
  35  * encoding
  36  */
  37  if ( extension_loaded('mbstring')) {
  38      /*
  39       * Joomla modification - As of PHP 8, the `mbstring.func_overload` configuration has been removed and the
  40       * MB_OVERLOAD_STRING constant will no longer be present, so this check only runs for PHP 7 and older
  41       * See https://github.com/php/php-src/commit/331e56ce38a91e87a6fb8e88154bb5bde445b132
  42       * and https://github.com/php/php-src/commit/97df99a6d7d96a886ac143337fecad775907589a
  43       * for additional references
  44       */
  45      if ( PHP_VERSION_ID < 80000 && ((int) ini_get('mbstring.func_overload')) & MB_OVERLOAD_STRING ) {
  46          trigger_error('String functions are overloaded by mbstring',E_USER_ERROR);
  47      }
  48      mb_internal_encoding('UTF-8');
  49  }
  50  
  51  /**
  52  * Check whether PCRE has been compiled with UTF-8 support
  53  */
  54  $UTF8_ar = array();
  55  if ( preg_match('/^.{1}$/u',"ñ",$UTF8_ar) != 1 ) {
  56      trigger_error('PCRE is not compiled with UTF-8 support',E_USER_ERROR);
  57  }
  58  unset($UTF8_ar);
  59  
  60  
  61  /**
  62  * Load the smartest implementations of utf8_strpos, utf8_strrpos
  63  * and utf8_substr
  64  */
  65  if ( !defined('UTF8_CORE') ) {
  66      if ( function_exists('mb_substr') ) {
  67          require_once  UTF8 . '/mbstring/core.php';
  68      } else {
  69          require_once  UTF8 . '/utils/unicode.php';
  70          require_once  UTF8 . '/native/core.php';
  71      }
  72  }
  73  
  74  /**
  75  * Load the native implementation of utf8_substr_replace
  76  */
  77  require_once  UTF8 . '/substr_replace.php';
  78  
  79  /**
  80  * You should now be able to use all the other utf_* string functions
  81  */


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer