From 198cd4062b7aede6e65e160ca499829f07043ee8 Mon Sep 17 00:00:00 2001 From: Robert Rohde Date: Mon, 30 Mar 2009 19:11:48 +0000 Subject: [PATCH] Adds fallback implementations of mb_strpos and mb_strrpos if native multi-byte support is not available. See comments 65, 66, 68 on bug 6455. --- includes/GlobalFunctions.php | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index f5eb274677..db30c459dc 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -72,6 +72,54 @@ if ( !function_exists( 'mb_strlen' ) ) { } } + +if( !function_exists( 'mb_strpos' ) ) { + /** + * Fallback implementation of mb_strpos, hardcoded to UTF-8. + * @param string $haystack + * @param string $needle + * @param string $offset optional start position + * @param string $encoding optional encoding; ignored + * @return int + */ + function mb_strpos( $haystack, $needle, $offset = 0, $encoding="" ) { + $needle = preg_quote( $needle, '/' ); + + $ar = array(); + preg_match( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); + + if( isset( $ar[0][1] ) ) { + return $ar[0][1]; + } else { + return false; + } + } +} + +if( !function_exists( 'mb_strrpos' ) ) { + /** + * Fallback implementation of mb_strrpos, hardcoded to UTF-8. + * @param string $haystack + * @param string $needle + * @param string $offset optional start position + * @param string $encoding optional encoding; ignored + * @return int + */ + function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = "" ) { + $needle = preg_quote( $needle, '/' ); + + $ar = array(); + preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); + + if( isset( $ar[0] ) && count( $ar[0] ) > 0 && + isset( $ar[0][count($ar[0])-1][1] ) ) { + return $ar[0][count($ar[0])-1][1]; + } else { + return false; + } + } +} + if ( !function_exists( 'array_diff_key' ) ) { /** * Exists in PHP 5.1.0+ -- 2.20.1