preg_match for hebrew 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
metalball
Forum Newbie
Posts: 2
Joined: Sun Nov 22, 2009 4:59 am

preg_match for hebrew characters?

Post by metalball »

hey all,

i'm trying to make this function:

Code: Select all

    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z0-9_\ -])+$/i", $str)) ? FALSE : TRUE;
    }
 
check also hebrew characters, but i fail every time...

i've tried:

Code: Select all

    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z\x{5D0}-\x{5EA}0-9_\ -])+$/i", $str)) ? FALSE : TRUE;
    }
 
but its no good...
also

Code: Select all

    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z?-?0-9_\ -])+$/i", $str)) ? FALSE : TRUE;
    }
 
same thing...

how can it be done?

thanx...
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: preg_match for hebrew characters?

Post by Apollo »

PHP's preg_* functions are based on PCRE, you need to add the u (unicode) modifer at the end (so "$/iu") for this to work.
metalball
Forum Newbie
Posts: 2
Joined: Sun Nov 22, 2009 4:59 am

Re: preg_match for hebrew characters?

Post by metalball »

:drunk:
thanx ALOT!
worked like a charm...

working code if anyone interested:

Code: Select all

 
    function alpha_space($str)
    {
        return ( ! preg_match("/^([-a-z\x{5D0}-\x{5EA}0-9_\ -])+$/iu", $str)) ? FALSE : TRUE;
    }
 
Post Reply