1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / stringNative.lib.php
blob3bc11cafa5df94513640ea43f763c277c12f73ad
1 <?php
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.
8 * @package PhpMyAdmin
9 */
10 if (!defined('PHPMYADMIN')) {
11 exit;
14 //Define mb_* functions if they don't exist.
15 if (!@function_exists('mb_strlen')) {
16 /**
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);
28 /**
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) {
40 return '';
42 if (null === $length) {
43 $length = 2147483647;
45 return substr($string, $start, $length);
48 /**
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);
61 /**
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);
75 /**
76 * Returns position of $needle in $haystack - case insensitive - or false if
77 * not found
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)
88 ) {
89 return false;
91 return stripos($haystack, $needle, $offset);
94 /**
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
110 * if not found
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)
122 return false;
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
145 * if not found
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
160 * if not found
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
166 * false
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);
198 //New functions.
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)
211 $matches = array();
212 $bFind = preg_match(
213 $pattern, $subject, $matches, PREG_OFFSET_CAPTURE, $offset
215 if (1 !== $bFind) {
216 return false;
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)
231 return 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)
243 return chr($ascii);