Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/
Share on other sites

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()?

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188524
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188588
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/230812-regex-and-cyrillic/#findComment-1188855
Share on other sites

  • 4 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.