preg_match() and japanese characters

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MaestroS
Forum Newbie
Posts: 2
Joined: Fri Dec 03, 2010 2:06 pm

preg_match() and japanese characters

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: preg_match() and japanese characters

Post by requinix »

Code: Select all

\x3oFF
MaestroS
Forum Newbie
Posts: 2
Joined: Fri Dec 03, 2010 2:06 pm

Re: preg_match() and japanese characters

Post by MaestroS »

Thank you. Problem solved.
Last edited by MaestroS on Fri Dec 03, 2010 4:18 pm, edited 1 time in total.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: preg_match() and japanese characters

Post by greyhoundcode »

Could it be an o as in orange when a 0 like 0.000 is required? As in, a typo?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: preg_match() and japanese characters

Post 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.
Post Reply