0 if str1 is greater than str2, and 0 if they are equal. * @see http://www.php.net/strcasecmp */ function strcasecmp($str1, $str2) { jimport('phputf8.strcasecmp'); return utf8_strcasecmp($str1, $str2); } /** * UTF-8 aware alternative to strcspn * Find length of initial segment not matching mask * * @static * @access public * @param string * @param string the mask * @param int Optional starting character position (in characters) * @param int Optional length * @return int the length of the initial segment of str1 which does not contain any of the characters in str2 * @see http://www.php.net/strcspn */ function strcspn($str, $mask, $start = NULL, $length = NULL) { jimport('phputf8.strcspn'); if ( $start === FALSE && $length === FALSE ) { return utf8_strcspn($str, $mask); } else if ( $length === FALSE ) { return utf8_strcspn($str, $mask, $start); } else { return utf8_strcspn($str, $mask, $start, $length); } } /** * UTF-8 aware alternative to stristr * Returns all of haystack from the first occurrence of needle to the end. * needle and haystack are examined in a case-insensitive manner * Find first occurrence of a string using case insensitive comparison * * @static * @access public * @param string the haystack * @param string the needle * @return string the sub string * @see http://www.php.net/stristr */ function stristr($str, $search) { jimport('phputf8.stristr'); return utf8_stristr($str, $search); } /** * UTF-8 aware alternative to strrev * Reverse a string * * @static * @access public * @param string String to be reversed * @return string The string in reverse character order * @see http://www.php.net/strrev */ function strrev($str) { jimport('phputf8.strrev'); return utf8_strrev($str); } /** * UTF-8 aware alternative to strspn * Find length of initial segment matching mask * * @static * @access public * @param string the haystack * @param string the mask * @param int start optional * @param int length optional * @see http://www.php.net/strspn */ function strspn($str, $mask, $start = NULL, $length = NULL) { jimport('phputf8.strspn'); if ( $start === FALSE && $length === FALSE ) { return utf8_strspn($str, $mask); } else if ( $length === FALSE ) { return utf8_strspn($str, $mask, $start); } else { return utf8_strspn($str, $mask, $start, $length); } } /** * UTF-8 aware substr_replace * Replace text within a portion of a string * * @static * @access public * @param string the haystack * @param string the replacement string * @param int start * @param int length (optional) * @see http://www.php.net/substr_replace */ function substr_replace($str, $repl, $start, $length = NULL ) { // loaded by library loader if ( $length === FALSE ) { return utf8_substr_replace($str, $repl, $start); } else { return utf8_substr_replace($str, $repl, $start, $length); } } /** * UTF-8 aware replacement for ltrim() * Strip whitespace (or other characters) from the beginning of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise ltrim will * work normally on a UTF-8 string * * @static * @access public * @param string the string to be trimmed * @param string the optional charlist of additional characters to trim * @return string the trimmed string * @see http://www.php.net/ltrim */ function ltrim( $str, $charlist = FALSE ) { jimport('phputf8.trim'); if ( $charlist === FALSE ) { return utf8_ltrim( $str ); } else { return utf8_ltrim( $str, $charlist ); } } /** * UTF-8 aware replacement for rtrim() * Strip whitespace (or other characters) from the end of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise rtrim will * work normally on a UTF-8 string * * @static * @access public * @param string the string to be trimmed * @param string the optional charlist of additional characters to trim * @return string the trimmed string * @see http://www.php.net/rtrim */ function rtrim( $str, $charlist = FALSE ) { jimport('phputf8.trim'); if ( $charlist === FALSE ) { return utf8_rltrim( $str ); } else { return utf8_rtrim( $str, $charlist ); } } /** * UTF-8 aware replacement for trim() * Strip whitespace (or other characters) from the beginning and end of a string * Note: you only need to use this if you are supplying the charlist * optional arg and it contains UTF-8 characters. Otherwise trim will * work normally on a UTF-8 string * * @static * @access public * @param string the string to be trimmed * @param string the optional charlist of additional characters to trim * @return string the trimmed string * @see http://www.php.net/trim */ function trim( $str, $charlist = FALSE ) { jimport('phputf8.trim'); if ( $charlist === FALSE ) { return utf8_trim( $str ); } else { return utf8_trim( $str, $charlist ); } } /** * UTF-8 aware alternative to ucfirst * Make a string's first character uppercase * * @static * @access public * @param string * @return string with first character as upper case (if applicable) * @see http://www.php.net/ucfirst */ function ucfirst($str) { jimport('phputf8.ucfirst'); return utf8_ucfirst($str); } /** * UTF-8 aware alternative to ucwords * Uppercase the first character of each word in a string * * @static * @access public * @param string * @return string with first char of each word uppercase * @see http://www.php.net/ucwords */ function ucwords($str) { jimport('phputf8.ucwords'); return utf8_ucwords($str); } /** * Transcode a string. * * @static * @param string $source The string to transcode. * @param string $from_encoding The source encoding. * @param string $to_encoding The target encoding. * @return string Transcoded string * @since 1.5 */ function transcode($source, $from_encoding, $to_encoding) { if (is_string($source)) { /* * "//TRANSLIT" is appendd to the $to_encoding to ensure that when iconv comes * across a character that cannot be represented in the target charset, it can * be approximated through one or several similarly looking characters. */ return iconv($from_encoding, $to_encoding.'//TRANSLIT', $source); } } }