Page 1 of 1

preg_match() and japanese characters

Posted: Fri Dec 03, 2010 2:13 pm
by MaestroS
This is my function:

Code: Select all

	function protect_content($var) {
		$specialChars = preg_quote('!@#$%^&*()/*-+=[]{};:\'",.<>?', '/');
		$pattern = '/
			^[
			\w\s
			' . $specialChars . '
			\x30A0-\x3oFF
			\x3040-\x309F
			\x4E00-\x9FBF
			\x3000-\x303F
			]*$
			/xu';
		
		if (!preg_match($pattern, $var)) { return false; } else { 
		 return true;
		}
	}
And whenever any data is being sent I got this error:
Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 82 in C:\Program Files\(path)\functions_class.php on line 60

Re: preg_match() and japanese characters

Posted: Fri Dec 03, 2010 2:47 pm
by requinix

Code: Select all

\x3oFF

Re: preg_match() and japanese characters

Posted: Fri Dec 03, 2010 3:31 pm
by MaestroS
Thank you. Problem solved.

Re: preg_match() and japanese characters

Posted: Fri Dec 03, 2010 3:40 pm
by greyhoundcode
Could it be an o as in orange when a 0 like 0.000 is required? As in, a typo?

Re: preg_match() and japanese characters

Posted: Fri Dec 03, 2010 4:33 pm
by requinix
greyhoundcode wrote:Could it be an o as in orange when a 0 like 0.000 is required? As in, a typo?
Yes. 0x30FF in Unicode is the end of the (Japanese) katakana alphabet. 0x3oFF isn't valid hexadecimal: preg_match assumes you want the character 0x3, but since it requires that character set ranges are from low to high, it crashes.