2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /** String Functions for phpMyAdmin
4 * If mb_* functions don't exist, we create the ones we need and they'll use the
5 * standard string functions.
6 * All mb_* functions created by PMA should behave as mb_* functions.
10 if (!defined('PHPMYADMIN')) {
14 //Define mb_* functions if they don't exist.
15 if (!@function_exists
('mb_strlen')) {
17 * Returns length of string depending on current charset.
19 * @param string $string string to count
21 * @return int string length
23 function mb_strlen($string)
25 return strlen($string);
29 * Returns substring from string, works depending on current charset.
31 * @param string $string string to count
32 * @param int $start start of substring
33 * @param int $length length of substring
35 * @return string the sub string
37 function mb_substr($string, $start, $length = 2147483647)
39 if (null === $string ||
strlen($string) <= $start) {
42 if (null === $length) {
45 return substr($string, $start, $length);
49 * Returns number of substring from string.
51 * @param string $string string to check
52 * @param int $needle string to count
54 * @return int number of substring from the string
56 function mb_substrCount($string, $needle)
58 return substr_count($string, $needle);
62 * Returns position of $needle in $haystack or false if not found
64 * @param string $haystack the string being checked
65 * @param string $needle the string to find in haystack
66 * @param int $offset the search offset
68 * @return integer position of $needle in $haystack or false
70 function mb_strpos($haystack, $needle, $offset = 0)
72 return strpos($haystack, $needle, $offset);
76 * Returns position of $needle in $haystack - case insensitive - or false if
79 * @param string $haystack the string being checked
80 * @param string $needle the string to find in haystack
81 * @param int $offset the search offset
83 * @return integer position of $needle in $haystack or false
85 function mb_stripos($haystack, $needle, $offset = 0)
87 if (('' === $haystack ||
false === $haystack) && $offset >= strlen($haystack)
91 return stripos($haystack, $needle, $offset);
95 * Returns position of last $needle in $haystack or false if not found
97 * @param string $haystack the string being checked
98 * @param string $needle the string to find in haystack
99 * @param int $offset the search offset
101 * @return integer position of last $needle in $haystack or false
103 function mb_strrpos($haystack, $needle, $offset = 0)
105 return strrpos($haystack, $needle, $offset);
109 * Returns position of last $needle in $haystack - case insensitive - or false
112 * @param string $haystack the string being checked
113 * @param string $needle the string to find in haystack
114 * @param int $offset the search offset
116 * @return integer position of last $needle in $haystack or false
118 function mb_strripos($haystack, $needle, $offset = 0)
120 if (('' === $haystack ||
false === $haystack) && $offset >= strlen($haystack)
124 return strripos($haystack, $needle, $offset);
128 * Returns part of $haystack string starting from and including the first
129 * occurrence of $needle to the end of $haystack or false if not found
131 * @param string $haystack the string being checked
132 * @param string $needle the string to find in haystack
133 * @param bool $before_needle the part before the needle
135 * @return string part of $haystack or false
137 function mb_strstr($haystack, $needle, $before_needle = false)
139 return strstr($haystack, $needle, $before_needle);
143 * Returns part of $haystack string starting from and including the first
144 * occurrence of $needle to the end of $haystack - case insensitive - or false
147 * @param string $haystack the string being checked
148 * @param string $needle the string to find in haystack
149 * @param bool $before_needle the part before the needle
151 * @return string part of $haystack or false
153 function mb_stristr($haystack, $needle, $before_needle = false)
155 return stristr($haystack, $needle, $before_needle);
159 * Returns the portion of haystack which starts at the last occurrence or false
162 * @param string $haystack the string being checked
163 * @param string $needle the string to find in haystack
165 * @return string portion of haystack which starts at the last occurrence or
168 function mb_strrchr($haystack, $needle)
170 return strrchr($haystack, $needle);
174 * Make a string lowercase
176 * @param string $string the string being lowercased
178 * @return string the lower case string
180 function mb_strtolower($string)
182 return strtolower($string);
186 * Make a string uppercase
188 * @param string $string the string being uppercased
190 * @return string the upper case string
192 function mb_strtoupper($string)
194 return strtoupper($string);
199 if (!@function_exists
('mb_ord')) {
201 * Perform a regular expression match
203 * @param string $pattern Pattern to search for
204 * @param string $subject Input string
205 * @param int $offset Start from search
207 * @return int 1 if matched, 0 if doesn't, false on failure
209 function mb_preg_strpos($pattern, $subject, $offset = 0)
213 $pattern, $subject, $matches, PREG_OFFSET_CAPTURE
, $offset
219 return $matches[1][1];
223 * Get the ordinal value of a string
225 * @param string $string the string for which ord is required
227 * @return int the ord value
229 function mb_ord($string)
235 * Get the character of an ASCII
237 * @param int $ascii the ASCII code for which character is required
239 * @return string the character
241 function mb_chr($ascii)