stringMb.lib.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /** String Functions for phpMyAdmin
  4. *
  5. * If mb_* functions don't exist, we create the ones we need and they'll use the
  6. * standard string functions.
  7. *
  8. * All mb_* functions created by pMA should behave as mb_* functions.
  9. *
  10. * @package PhpMyAdmin
  11. */
  12. if (! defined('PHPMYADMIN')) {
  13. exit;
  14. }
  15. if (!@function_exists('mb_ord')) {
  16. /**
  17. * Perform a regular expression match
  18. *
  19. * Take care: might not work with lookbehind expressions.
  20. *
  21. * @param string $pattern Pattern to search for
  22. * @param string $subject Input string
  23. * @param int $offset Start from search
  24. *
  25. * @return int 1 if matched, 0 if doesn't, false on failure
  26. */
  27. function mb_preg_strpos($pattern, $subject, $offset = 0)
  28. {
  29. $matches = array();
  30. $bFind = preg_match(
  31. $pattern, mb_substr($subject, $offset), $matches, PREG_OFFSET_CAPTURE
  32. );
  33. if (1 !== $bFind) {
  34. return false;
  35. }
  36. return $matches[1][1] + $offset;
  37. }
  38. /**
  39. * Get the ordinal value of a string
  40. *
  41. * @param string $string the string for which ord is required
  42. *
  43. * @return int the ord value
  44. */
  45. function mb_ord($string)
  46. {
  47. if (false === $string || null === $string || '' === $string) {
  48. return 0;
  49. }
  50. $str = mb_convert_encoding($string, "UCS-4BE", "UTF-8");
  51. $substr = mb_substr($str, 0, 1, "UCS-4BE");
  52. $val = unpack("N", $substr);
  53. return $val[1];
  54. }
  55. /**
  56. * Get the character of an ASCII
  57. *
  58. * @param int $ascii the ASCII code for which character is required
  59. *
  60. * @return string the character
  61. */
  62. function mb_chr($ascii)
  63. {
  64. return mb_convert_encoding(
  65. pack("N", $ascii),
  66. mb_internal_encoding(),
  67. 'UCS-4BE'
  68. );
  69. }
  70. }