yaxar Posted March 16, 2011 Share Posted March 16, 2011 I am trying to check if a string is Cyrillic but so far it is not working. This is my code so far. $str = 'ырөлоырөб'; if (preg_match('{Script=Cyrillic}/iu*', $str)) { echo 'it works'; }else { echo 'it dosent work'; } When i tried it on my server it outputed 'it dosent work'. can you help me and find if their is anything wrong with the regex expression. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/ Share on other sites More sharing options...
btherl Posted March 17, 2011 Share Posted March 17, 2011 The comments here look relevant (see below in the responses where someone discusses PHP and Cyrillic): http://stackoverflow.com/questions/4907342/javascript-regexp-cyrillic-pattern Also are you sure your cyrillic string is encoded in UTF8 when it goes into the preg_match()? Quote Link to comment https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188524 Share on other sites More sharing options...
yaxar Posted March 17, 2011 Author Share Posted March 17, 2011 The comments here look relevant (see below in the responses where someone discusses PHP and Cyrillic): http://stackoverflow.com/questions/4907342/javascript-regexp-cyrillic-pattern The regex expression they gave there "[\s\p{IsCyrillic}]" outputs an error Message: preg_match() [function.preg-match]: Compilation failed: unknown property name after \P or \p at offset 15 Also are you sure your Cyrillic string is encoded in UTF8 when it goes into the preg_match()? And yes it is be Cyrillic. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188588 Share on other sites More sharing options...
btherl Posted March 17, 2011 Share Posted March 17, 2011 According to the comments on that site it's \p{Cyrillic}, and it will only work if PHP was compiled with a regexp library which supports that. But you can still do it like this: $pattern = "/[абвгдАБВГД]/"; preg_match($pattern, $str); And if you list every possible cyrillic character in there, it'll work.. Quote Link to comment https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188855 Share on other sites More sharing options...
petelko23 Posted August 5, 2011 Share Posted August 5, 2011 see this post, there is an explanation how to use preg_match with non-Latin utf8 characters (Cyrilic, Arabic, Greek): http://itworkarounds.blogspot.com/2011/08/validating-cyrillic-utf8-alphanumeric.html Quote Link to comment https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1252409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.