// The followind options may be used in limited number of places for overriding the common convention:
define('PERSON_NAME_WESTERN_ORDER', 1); // Formatting a person's name in Western order: first_name last_name
define('PERSON_NAME_EASTERN_ORDER', 2); // Formatting a person's name in Eastern order: last_name first_name
define('PERSON_NAME_LIBRARY_ORDER', 3); // Contextual: formatting person's name in library order: last_name, first_name
define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER); // Contextual: formatting a person's name assotiated with an email-address. Ivan: I am not sure how seems email servers an clients would interpret name order, so I assign the Western order.
define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER); // Contextual: formatting a person's name for data-exporting operarions. For backward compatibility this format has been set to Eastern order.
// There is no cached translation, we have to retrieve it:
// - from a global variable (the faster way) - on production server mode;
// - from a local variable after reloading the language files - on test server mode or when requested language is different than the genuine interface language.
* @param bool $purified (optional) When it is true, a purified (refined) language value will be returned, for example 'french' instead of 'french_unicode'.
* @return string The current language of the interface.
* Returns a DATETIME string converted to the right timezone
* @param mixed The time to be converted
* @param string The timezone to be converted to. If null, the timezone will be determined based on user preference, or timezone chosen by the admin for the platform.
* @param string The timezone to be converted from. If null, UTC will be assumed.
* @return string The converted time formatted as Y-m-d H:i:s
* @param mixed Date format (string or int; see date formats in the Chamilo system: TIME_NO_SEC_FORMAT, DATE_FORMAT_SHORT, DATE_FORMAT_LONG, DATE_TIME_FORMAT_LONG)
* @param int/string $format (optional) The person name format. It may be a pattern-string (for example '%t %l, %f' or '%T %F %L', ...) or some of the constants PERSON_NAME_COMMON_CONVENTION (default), PERSON_NAME_WESTERN_ORDER, PERSON_NAME_EASTERN_ORDER, PERSON_NAME_LIBRARY_ORDER.
* @param string $language (optional) The language indentificator. If it is omited, the current interface language is assumed. This parameter has meaning with the format PERSON_NAME_COMMON_CONVENTION only.
* @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.
* Note: See the file chamilo/main/inc/lib/internationalization_database/name_order_conventions.php where you can revise the convention for your language.
* Checks whether a given format represents person name in Western order (for which first name is first).
* @param int/string $format (optional) The person name format. It may be a pattern-string (for example '%t. %l, %f') or some of the constants PERSON_NAME_COMMON_CONVENTION (default), PERSON_NAME_WESTERN_ORDER, PERSON_NAME_EASTERN_ORDER, PERSON_NAME_LIBRARY_ORDER.
* @param string $language (optional) The language indentificator. If it is omited, the current interface language is assumed. This parameter has meaning with the format PERSON_NAME_COMMON_CONVENTION only.
* @return bool The result TRUE means that the order is first_name last_name, FALSE means last_name first_name.
* Note: You may use this function for determing the order of the fields or columns "First name" and "Last name" in forms, tables and reports.
* @author Ivan Tcholakov
*/
function api_is_western_name_order($format = null, $language = null) {
* This function returns a string or an array with all occurrences of search in subject (ignoring case) replaced with the given replace value.
* @param mixed $search String or array of strings to be found.
* @param mixed $replace String or array of strings used for replacement.
* @param mixed $subject String or array of strings being searced.
* @param int $count (optional) The number of matched and replaced needles will be returned in count, which is passed by reference.
* @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 mixed String or array as a result.
* Notes:
* If $subject is an array, then the search and replace is performed with every entry of subject, the return value is an array.
* If $search and $replace are arrays, then the function takes a value from each array and uses it to do search and replace on subject.
* If $replace has fewer values than search, then an empty string is used for the rest of replacement values.
* If $search is an array and $replace is a string, then this replacement string is used for every value of search.
* This function is aimed at replacing the function str_ireplace() for human-language strings.
* @param int $split_length Maximum character-length of the chunk, one character by default.
* @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 array The result array of chunks with the spcified length.
* Notes:
* If the optional split_length parameter is specified, the returned array will be broken down into chunks
* with each being split_length in length, otherwise each chunk will be one character in length.
* FALSE is returned if split_length is less than 1.
* If the split_length length exceeds the length of string, the entire string is returned as the first (and only) array element.
* This function is aimed at replacing the function str_split() for human-language strings.
* @link http://php.net/str_split
*/
function api_str_split($string, $split_length = 1, $encoding = null) {
* Finds position of first occurrence of a string within another, case insensitive.
* @param string $haystack The string from which to get the position of the first occurrence.
* @param string $needle The string to be found.
* @param int $offset The position in $haystack to start searching from. If it is omitted, searching starts from the beginning.
* @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 mixed Returns the numeric position of the first occurrence of $needle in the $haystack, or FALSE if $needle is not found.
* Note: The first character's position is 0, the second character position is 1, and so on.
* This function is aimed at replacing the functions stripos() and mb_stripos() for human-language strings.
* Finds first occurrence of a string within another, case insensitive.
* @param string $haystack The string from which to get the first occurrence.
* @param mixed $needle The string to be found.
* @param bool $before_needle (optional) Determines which portion of $haystack this function returns. The default value is 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 mixed Returns the portion of $haystack, or FALSE if $needle is not found.
* Notes:
* If $needle is not a string, it is converted to an integer and applied as the ordinal value (codepoint if the encoding is UTF-8) of a character.
* If $before_needle is set to TRUE, the function returns all of $haystack from the beginning to the first occurrence of $needle.
* If $before_needle is set to FALSE, the function returns all of $haystack from the first occurrence of $needle to the end.
* This function is aimed at replacing the functions stristr() and mb_stristr() for human-language strings.
* @param string $string The string which length is to be calculated.
* @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 the number of characters within the string. A multi-byte character is counted as 1.
* This function is aimed at replacing the functions strlen() and mb_strlen() for human-language strings.
* Finds position of first occurrence of a string within another.
* @param string $haystack The string from which to get the position of the first occurrence.
* @param string $needle The string to be found.
* @param int $offset (optional) The position in $haystack to start searching from. If it is omitted, searching starts from the beginning.
* @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 mixed Returns the numeric position of the first occurrence of $needle in the $haystack, or FALSE if $needle is not found.
* Note: The first character's position is 0, the second character position is 1, and so on.
* This function is aimed at replacing the functions strpos() and mb_strpos() for human-language strings.
* Finds the last occurrence of a character in a string.
* @param string $haystack The string from which to get the last occurrence.
* @param mixed $needle The string which first character is to be found.
* @param bool $before_needle (optional) Determines which portion of $haystack this function returns. The default value is 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 mixed Returns the portion of $haystack, or FALSE if the first character from $needle is not found.
* Notes:
* If $needle is not a string, it is converted to an integer and applied as the ordinal value (codepoint if the encoding is UTF-8) of a character.
* If $before_needle is set to TRUE, the function returns all of $haystack from the beginning to the first occurrence.
* If $before_needle is set to FALSE, the function returns all of $haystack from the first occurrence to the end.
* This function is aimed at replacing the functions strrchr() and mb_strrchr() for human-language strings.
* @param string $string The string to be reversed.
* @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 string Returns the reversed string.
* This function is aimed at replacing the function strrev() for human-language strings.
* Finds the position of last occurrence (case insensitive) of a string in a string.
* @param string $haystack The string from which to get the position of the last occurrence.
* @param string $needle The string to be found.
* @param int $offset (optional) $offset may be specified to begin searching an arbitrary position. Negative values will stop searching at an arbitrary point prior to the end of the string.
* @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 mixed Returns the numeric position of the first occurrence (case insensitive) of $needle in the $haystack, or FALSE if $needle is not found.
* Note: The first character's position is 0, the second character position is 1, and so on.
* This function is aimed at replacing the functions strripos() and mb_strripos() for human-language strings.
* Finds the position of last occurrence of a string in a string.
* @param string $haystack The string from which to get the position of the last occurrence.
* @param string $needle The string to be found.
* @param int $offset (optional) $offset may be specified to begin searching an arbitrary position. Negative values will stop searching at an arbitrary point prior to the end of the string.
* @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 mixed Returns the numeric position of the first occurrence of $needle in the $haystack, or FALSE if $needle is not found.
* Note: The first character's position is 0, the second character position is 1, and so on.
* This function is aimed at replacing the functions strrpos() and mb_strrpos() for human-language strings.
* Finds first occurrence of a string within another.
* @param string $haystack The string from which to get the first occurrence.
* @param mixed $needle The string to be found.
* @param bool $before_needle (optional) Determines which portion of $haystack this function returns. The default value is 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 mixed Returns the portion of $haystack, or FALSE if $needle is not found.
* Notes:
* If $needle is not a string, it is converted to an integer and applied as the ordinal value (codepoint if the encoding is UTF-8) of a character.
* If $before_needle is set to TRUE, the function returns all of $haystack from the beginning to the first occurrence of $needle.
* If $before_needle is set to FALSE, the function returns all of $haystack from the first occurrence of $needle to the end.
* This function is aimed at replacing the functions strstr() and mb_strstr() for human-language strings.
* @param string $string The string being lowercased.
* @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 string Returns the string with all alphabetic characters converted to lowercase.
* This function is aimed at replacing the functions strtolower() and mb_strtolower() for human-language strings.
* @param string $string The string being uppercased.
* @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 string Returns the string with all alphabetic characters converted to uppercase.
* This function is aimed at replacing the functions strtoupper() and mb_strtoupper() for human-language strings.
* @param int $start The first position from which the extracted part begins.
* @param int $length The length in character of the extracted part.
* @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 string Returns the part of the string specified by the start and length parameters.
* Note: First character's position is 0. Second character position is 1, and so on.
* This function is aimed at replacing the functions substr() and mb_substr() for human-language strings.
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @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 The number of times the needle substring occurs in the haystack string.
* @param string $replacement The replacement string.
* @param int $start The position from which replacing will begin.
* Notes:
* If $start is positive, the replacing will begin at the $start'th offset into the string.
* If $start is negative, the replacing will begin at the $start'th character from the end of the string.
* @param int $length (optional) The position where replacing will end.
* Notes:
* If given and is positive, it represents the length of the portion of the string which is to be replaced.
* If it is negative, it represents the number of characters from the end of string at which to stop replacing.
* If it is not given, then it will default to api_strlen($string); i.e. end the replacing at the end of string.
* If $length is zero, then this function will have the effect of inserting replacement into the string at the given start offset.
* @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 string The result string is returned.
* This function is aimed at replacing the function substr_replace() for human-language strings.
* @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 string Returns a string with the first character capitalized, if that character is alphabetic.
* This function is aimed at replacing the function ucfirst() for human-language strings.
* Uppercases the first character of each word in a string.
* @param string $string The input string.
* @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 string Returns the modified string.
* This function is aimed at replacing the function ucwords() for human-language strings.
* Performs a regular expression match, UTF-8 aware when it is applicable.
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param array &$matches (optional) If matches is provided, then it is filled with the results of search (as an array).
* $matches[0] will contain the text that matched the full pattern, $matches[1] will have the text that matched the first captured parenthesized subpattern, and so on.
* @param int $flags (optional) Could be PREG_OFFSET_CAPTURE. If this flag is passed, for every occurring match the appendant string offset will also be returned.
* Note that this changes the return value in an array where every element is an array consisting of the matched string at index 0 and its string offset into subject at index 1.
* @param int $offset (optional) Normally, the search starts from the beginning of the subject string. The optional parameter offset can be used to specify the alternate place from which to start the search.
* @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|boolean Returns the number of times pattern matches or FALSE if an error occurred.
* Performs a global regular expression match, UTF-8 aware when it is applicable.
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param array &$matches (optional) Array of all matches in multi-dimensional array ordered according to $flags.
* @param int $flags (optional) Can be a combination of the following flags (note that it doesn't make sense to use PREG_PATTERN_ORDER together with PREG_SET_ORDER):
* PREG_PATTERN_ORDER - orders results so that $matches[0] is an array of full pattern matches, $matches[1] is an array of strings matched by the first parenthesized subpattern, and so on;
* PREG_SET_ORDER - orders results so that $matches[0] is an array of first set of matches, $matches[1] is an array of second set of matches, and so on;
* PREG_OFFSET_CAPTURE - If this flag is passed, for every occurring match the appendant string offset will also be returned. Note that this changes the value of matches
* in an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1.
* If no order flag is given, PREG_PATTERN_ORDER is assumed.
* @param int $offset (optional) Normally, the search starts from the beginning of the subject string. The optional parameter offset can be used to specify the alternate place from which to start the search.
* @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|boolean Returns the number of full pattern matches (which might be zero), or FALSE if an error occurred.
* Performs a regular expression search and replace, UTF-8 aware when it is applicable.
* @param string|array $pattern The pattern to search for. It can be either a string or an array with strings.
* @param string|array $replacement The string or an array with strings to replace.
* @param string|array $subject The string or an array with strings to search and replace.
* @param int $limit The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).
* @param int &$count If specified, this variable will be filled with the number of replacements done.
* @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 array|string|null returns an array if the subject parameter is an array, or a string otherwise.
* If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or NULL if an error occurred.
* Performs a regular expression search and replace using a callback function, UTF-8 aware when it is applicable.
* @param string|array $pattern The pattern to search for. It can be either a string or an array with strings.
* @param function $callback A callback that will be called and passed an array of matched elements in the $subject string. The callback should return the replacement string.
* @param string|array $subject The string or an array with strings to search and replace.
* @param int $limit (optional) The maximum possible replacements for each pattern in each subject string. Defaults to -1 (no limit).
* @param int &$count (optional) If specified, this variable will be filled with the number of replacements done.
* @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 array|string Returns an array if the subject parameter is an array, or a string otherwise.
* Splits a string by a regular expression, UTF-8 aware when it is applicable.
* @param string $pattern The pattern to search for, as a string.
* @param string $subject The input string.
* @param int $limit (optional) If specified, then only substrings up to $limit are returned with the rest of the string being placed in the last substring. A limit of -1, 0 or null means "no limit" and, as is standard across PHP.
* @param int $flags (optional) $flags can be any combination of the following flags (combined with bitwise | operator):
* PREG_SPLIT_NO_EMPTY - if this flag is set, only non-empty pieces will be returned;
* PREG_SPLIT_DELIM_CAPTURE - if this flag is set, parenthesized expression in the delimiter pattern will be captured and returned as well;
* PREG_SPLIT_OFFSET_CAPTURE - If this flag is set, for every occurring match the appendant string offset will also be returned.
* Note that this changes the return value in an array where every element is an array consisting of the matched string at offset 0 and its string offset into subject at offset 1.
* @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 array Returns an array containing substrings of $subject split along boundaries matched by $pattern.
* Obsolete string operations using regular expressions, to be deprecated
*/
/**
* Note: Try to avoid using this function. Use api_preg_match() with Perl-compatible regular expression syntax.
*
* Executes a regular expression match with extended multibyte support.
* By default this function uses the platform character set.
* @param string $pattern The regular expression pattern.
* @param string $string The searched string.
* @param array $regs (optional) If specified, by this passed by reference parameter an array containing found match and its substrings is returned.
* @return mixed 1 if match is found, FALSE if not. If $regs has been specified, byte-length of the found match is returned, or FALSE if no match has been found.
* This function is aimed at replacing the functions ereg() and mb_ereg() for human-language strings.
* @link http://php.net/manual/en/function.ereg
* @link http://php.net/manual/en/function.mb-ereg
*/
function api_ereg($pattern, $string, & $regs = null) {
* 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.
* Note: Try to avoid using this function. Use api_preg_match() with Perl-compatible regular expression syntax.
*
* Executes a regular expression match, ignoring case, with extended multibyte support.
* By default this function uses the platform character set.
* @param string $pattern The regular expression pattern.
* @param string $string The searched string.
* @param array $regs (optional) If specified, by this passed by reference parameter an array containing found match and its substrings is returned.
* @return mixed 1 if match is found, FALSE if not. If $regs has been specified, byte-length of the found match is returned, or FALSE if no match has been found.
* This function is aimed at replacing the functions eregi() and mb_eregi() 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, 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 strcasecmp() for human-language strings.
* Performs string comparison, case sensitive, 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 strcmp() 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.
* Performs string comparison in so called "natural order", case sensitive, 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 strnatcmp() 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.
* @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 natsort() for sorting human-language strings.
* Sorts an array 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_natrsort(&$array, $language = null, $encoding = null) {
* 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.
* 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.
* 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 by keys 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_knatcasersort(&$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.
* 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.
* This function checks whether two $encoding are equal (same, equvalent).
* @param string/array $encoding1 The first encoding
* @param string/array $encoding2 The second encoding
* @param bool $strict When this parameter is TRUE the comparison ignores aliases of encodings. When the parameter is FALSE, aliases are taken into account.
* @return bool Returns TRUE if the encodings are equal, FALSE otherwise.
*/
function api_equal_encodings($encoding1, $encoding2, $strict = false) {