MyBB Community Forums

Full Version: [F] my_substr(): Problem with umlauts [C-Imad Jomaa]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I talked to Chris B. and we're working up a solution. Basically we'll add a setting and run unicode preg_matches based on that.

"Force Unicode Expression Matching?" Yes / No - Description: "This value will be set upon tests during installation/upgrade. It is best kept left at the default value, unless you know what you are doing."

And during the upgrade script we'll test a unicode string with the unicode modifier and we'll check if there are question marks. If there are that means it won't work with the Unicode modifier.

We may only implement this for 1.6 though because of the amount of testing it will take to make sure this workaround is stable across different hosts and different environments.
Try adding this to your inc/functions_compat.php

if(!function_exists('mb_substr'))
{
	/**
	 * Multibyte safe substr function. Based off of code from http://php.net/manual/en/function.substr.php#53199
	 *
	 * @param string The string to cut.
	 * @param int Where to start
	 * @param int (optional) How much to cut
	 * @return int The cut part of the string.
	 */
	function mb_substr($string, $start, $len=null)
	{
		// How many bytes per character does this string have? (ex. utf-8 is "3", gb2312 and big5 is "2")
		$byte = 3;
		$cut_string = "";
		$count = 0;
		$string_length = strlen($string);
		
		if($len == null)
		{
			$len = $string_length;
		}
		
		for($i=0; $i < $string_length; $i++)
		{
			$chr = substr($string, $i, 1);
			$ord = ord($chr);
			
			if(($count+1-$start) > $len)
			{
				break;
			}
			elseif($ord <= 128 && $count < $start)
			{
				$count++;
			}
			elseif($ord > 128 && $count < $start)
			{
				$count = $count+2;
				$i = $i+$byte-1;
			}
			elseif($ord <= 128 && $count >= $start)
			{
				$cut_string .= $chr;
				$count++;
			}
			elseif($ord > 128 && $count >= $start)
			{
				$cut_string .= substr($string, $i, $byte);
				$count = $count+2;
				$i = $i+$byte-1;
			}
		}
		return $cut_string;
	}
}

See if it works then
Thank you for your bug report.

This bug has been fixed in our internal code repository. Please note that the problem will not be fixed here until these forums are updated.

With regards,
MyBB Group
Pages: 1 2