Merge branch 'QA_4_4' into QA_4_5
[phpmyadmin.git] / libraries / stringMb.lib.php
blob652dde06b4338c566832a7ffc76e6c4824e26db4
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /** String Functions for phpMyAdmin
5 * If mb_* functions don't exist, we create the ones we need and they'll use the
6 * standard string functions.
8 * All mb_* functions created by pMA should behave as mb_* functions.
10 * @package PhpMyAdmin
12 if (! defined('PHPMYADMIN')) {
13 exit;
16 if (!@function_exists('mb_ord')) {
17 mb_internal_encoding('utf-8');
19 /**
20 * Perform a regular expression match
22 * Take care: might not work with lookbehind expressions.
24 * @param string $pattern Pattern to search for
25 * @param string $subject Input string
26 * @param int $offset Start from search
28 * @return int 1 if matched, 0 if doesn't, false on failure
30 function mb_preg_strpos($pattern, $subject, $offset = 0)
32 $matches = array();
33 $bFind = preg_match(
34 $pattern, mb_substr($subject, $offset), $matches, PREG_OFFSET_CAPTURE
36 if (1 !== $bFind) {
37 return false;
40 return $matches[1][1] + $offset;
43 /**
44 * Get the ordinal value of a string
46 * @param string $string the string for which ord is required
48 * @return int the ord value
50 function mb_ord($string)
52 if (false === $string || null === $string || '' === $string) {
53 return 0;
56 $str = mb_convert_encoding($string, "UCS-4BE", "UTF-8");
57 $substr = mb_substr($str, 0, 1, "UCS-4BE");
58 $val = unpack("N", $substr);
59 return $val[1];
62 /**
63 * Get the character of an ASCII
65 * @param int $ascii the ASCII code for which character is required
67 * @return string the character
69 function mb_chr($ascii)
71 return mb_convert_encoding(
72 pack("N", $ascii),
73 mb_internal_encoding(),
74 'UCS-4BE'