/** * Wrapper around mb_strrpos. * * Find position of last occurrence of a char in a string. * * @param string $str haystack * @param string $search needle (you should validate this with utf8_is_valid) * @param integer|false $offset (optional) offset (from left) * * @return mixed integer position or false on failure */ function rpos($str, $search, $offset = false) { $str = bad_clean($str); if (!$offset) { // Emulate behaviour of strrpos rather than raising warning if (empty($str)) { return false; } return mb_strrpos($str, $search); } if (!is_int($offset)) { trigger_error('utf8_strrpos expects parameter 3 to be long', E_USER_WARNING); return false; } $str = mb_substr($str, $offset); if (($pos = mb_strrpos($str, $search)) !== false) { return $pos + $offset; } return false; }
/** * Function: len. Unicode aware replacement for *strlen*. * * Returns the number of characters in the string (not the number of bytes), * replacing multibyte characters with a single byte equivalent utf8_decode * converts characters that are not in ISO-8859-1 to '?', which, for the purpose * of counting, is alright. It's much faster than iconv_strlen. * * Author: <chernyshevsky at hotmail dot com> * * @param string $str * * @return integer */ function len($str) { return strlen(utf8_decode(bad_clean($str))); }