* If i is specified for the matching condition parameter, the case will be ignored.
* If x is specified, white space will be ignored.
* If m is specified, match will be executed in multiline mode and line break will be included in '.'.
* If p is specified, match will be executed in POSIX mode, line break will be considered as normal character.
* If e is specified, replacement string will be evaluated as PHP expression.
* @return mixed The modified string is returned. If no matches are found within the string, then it will be returned unchanged. FALSE will be returned on error.
* This function is aimed at replacing the functions ereg_replace() and mb_ereg_replace() for human-language strings.
* If i is specified for the matching condition parameter, the case will be ignored.
* If x is specified, white space will be ignored.
* If m is specified, match will be executed in multiline mode and line break will be included in '.'.
* If p is specified, match will be executed in POSIX mode, line break will be considered as normal character.
* If e is specified, replacement string will be evaluated as PHP expression.
* @return mixed The modified string is returned. If no matches are found within the string, then it will be returned unchanged. FALSE will be returned on error.
* This function is aimed at replacing the functions eregi_replace() and mb_eregi_replace() for human-language strings.
* Performs string comparison in so called "natural order", case insensitive, language sensitive, with extended multibyte support.
* @param string $string1 The first string.
* @param string $string2 The second string.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return int Returns <0if$string1islessthan$string2;> 0 if $string1 is greater than $string2; and 0 if the strings are equal.
* This function is aimed at replacing the function strnatcasecmp() for human-language strings.
* Sorts an array with maintaining index association, elements will be arranged from the lowest to the highest.
* @param array $array The input array.
* @param int $sort_flag (optional) Shows how elements of the array to be compared.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* Note: $sort_flag may have the following values:
* SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types;
* SORT_NUMERIC - items will be compared as numbers;
* SORT_STRING - items will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale;
* SORT_LOCALE_STRING - items will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale.
* This function is aimed at replacing the function asort() for sorting human-language strings.
* Sorts an array with maintaining index association, elements will be arranged from the highest to the lowest (in reverse order).
* @param array $array The input array.
* @param int $sort_flag (optional) Shows how elements of the array to be compared.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* Note: $sort_flag may have the following values:
* SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types;
* SORT_NUMERIC - items will be compared as numbers;
* SORT_STRING - items will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale;
* SORT_LOCALE_STRING - items will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale.
* This function is aimed at replacing the function arsort() for sorting human-language strings.
* Sorts an array using natural order algorithm, case-insensitive.
* @param array $array The input array.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* This function is aimed at replacing the function natcasesort() for sorting human-language strings.
* Sorts an array using natural order algorithm, case-insensitive, reverse order.
* @param array $array The input array.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
*/
function api_natcasersort(&$array, $language = null, $encoding = null) {
* Sorts an array by keys, elements will be arranged from the lowest key to the highest key.
* @param array $array The input array.
* @param int $sort_flag (optional) Shows how keys of the array to be compared.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* Note: $sort_flag may have the following values:
* SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types;
* SORT_NUMERIC - keys will be compared as numbers;
* SORT_STRING - keys will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale;
* SORT_LOCALE_STRING - keys will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale.
* This function is aimed at replacing the function ksort() for sorting human-language key strings.
if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
global $_api_collator, $_api_encoding;
$_api_collator = $collator;
$_api_encoding = $encoding;
return uksort($array, '_api_cmp');
}
}
}
return ksort($array, $sort_flag);
}
/**
* Sorts an array by keys, elements will be arranged from the highest key to the lowest key (in reverse order).
* @param array $array The input array.
* @param int $sort_flag (optional) Shows how keys of the array to be compared.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* Note: $sort_flag may have the following values:
* SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types;
* SORT_NUMERIC - keys will be compared as numbers;
* SORT_STRING - keys will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale;
* SORT_LOCALE_STRING - keys will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale.
* This function is aimed at replacing the function krsort() for sorting human-language key strings.
if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
global $_api_collator, $_api_encoding;
$_api_collator = $collator;
$_api_encoding = $encoding;
return uksort($array, '_api_rcmp');
}
}
}
return krsort($array, $sort_flag);
}
/**
* Sorts an array by keys using natural order algorithm.
* @param array $array The input array.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
*/
function api_knatsort(&$array, $language = null, $encoding = null) {
* Sorts an array by keys using natural order algorithm in reverse order.
* @param array $array The input array.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
*/
function api_knatrsort(&$array, $language = null, $encoding = null) {
* Sorts an array by keys using natural order algorithm, case insensitive.
* @param array $array The input array.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
*/
function api_knatcasesort(&$array, $language = null, $encoding = null) {
* Sorts an array, elements will be arranged from the lowest to the highest.
* @param array $array The input array.
* @param int $sort_flag (optional) Shows how elements of the array to be compared.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* Note: $sort_flag may have the following values:
* SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types;
* SORT_NUMERIC - items will be compared as numbers;
* SORT_STRING - items will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale;
* SORT_LOCALE_STRING - items will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale.
* This function is aimed at replacing the function sort() for sorting human-language strings.
* Sorts an array, elements will be arranged from the highest to the lowest (in reverse order).
* @param array $array The input array.
* @param int $sort_flag (optional) Shows how elements of the array to be compared.
* @param string $language (optional) The language in which comparison is to be made. If language is omitted, interface language is assumed then.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE on success, FALSE on error.
* Note: $sort_flag may have the following values:
* SORT_REGULAR - internal PHP-rules for comparison will be applied, without preliminary changing types;
* SORT_NUMERIC - items will be compared as numbers;
* SORT_STRING - items will be compared as strings. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale;
* SORT_LOCALE_STRING - items will be compared as strings depending on the current POSIX locale. If intl extension is enabled, then comparison will be language-sensitive using internally a created ICU locale.
* This function is aimed at replacing the function rsort() for sorting human-language strings.
if ($sort_flag == SORT_STRING || $sort_flag == SORT_LOCALE_STRING) {
global $_api_collator, $_api_encoding;
$_api_collator = $collator;
$_api_encoding = $encoding;
return usort($array, '_api_rcmp');
}
}
}
return rsort($array, $sort_flag);
}
/**
* Common sting operations with arrays
*/
/**
* Checks if a value exists in an array, a case insensitive version of in_array() function with extended multibyte support.
* @param mixed $needle The searched value. If needle is a string, the comparison is done in a case-insensitive manner.
* @param array $haystack The array.
* @param bool $strict (optional) If is set to TRUE then the function will also check the types of the $needle in the $haystack. The default value if FALSE.
* @param string $encoding (optional) The used internally by this function character encoding. If it is omitted, the platform character set will be used by default.
* @return bool Returns TRUE if $needle is found in the array, FALSE otherwise.