/libraries/vendor/joomla/string/src/phputf8/utf8.php

https://gitlab.com/vitaliylukin91/idea-rating · PHP · 74 lines · 24 code · 7 blank · 43 comment · 8 complexity · cd88682ddce48e6d186288fa82925a8a MD5 · raw file

  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. * Put the current directory in this constant
  24. */
  25. if ( !defined('UTF8') ) {
  26. define('UTF8',dirname(__FILE__));
  27. }
  28. /**
  29. * If string overloading is active, it will break many of the
  30. * native implementations. mbstring.func_overload must be set
  31. * to 0, 1 or 4 in php.ini (string overloading disabled).
  32. * Also need to check we have the correct internal mbstring
  33. * encoding
  34. */
  35. if ( extension_loaded('mbstring')) {
  36. if ( ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING ) {
  37. trigger_error('String functions are overloaded by mbstring',E_USER_ERROR);
  38. }
  39. mb_internal_encoding('UTF-8');
  40. }
  41. /**
  42. * Check whether PCRE has been compiled with UTF-8 support
  43. */
  44. $UTF8_ar = array();
  45. if ( preg_match('/^.{1}$/u',"ñ",$UTF8_ar) != 1 ) {
  46. trigger_error('PCRE is not compiled with UTF-8 support',E_USER_ERROR);
  47. }
  48. unset($UTF8_ar);
  49. /**
  50. * Load the smartest implementations of utf8_strpos, utf8_strrpos
  51. * and utf8_substr
  52. */
  53. if ( !defined('UTF8_CORE') ) {
  54. if ( function_exists('mb_substr') ) {
  55. require_once UTF8 . '/mbstring/core.php';
  56. } else {
  57. require_once UTF8 . '/utils/unicode.php';
  58. require_once UTF8 . '/native/core.php';
  59. }
  60. }
  61. /**
  62. * Load the native implementation of utf8_substr_replace
  63. */
  64. require_once UTF8 . '/substr_replace.php';
  65. /**
  66. * You should now be able to use all the other utf_* string functions
  67. */