The Little Guy Posted December 20, 2012 Share Posted December 20, 2012 I am using the code (at the bottom) to test some strings for non-US characters, the following code is returning: int(0) int(0) int(0) The result I am looking for is the first and thrid dump should be 0 and the second dump should be 1 like so: int(0) int(1) int(0) Here is my test code: <?php $str[] = '漢語'; $str[] = 'abc123'; $str[] = '漢語abc123'; foreach($str as $s){ var_dump(preg_match("/^\p{Common}*$/u", $s, $matches)); } What can I do to get the results of the second block? Quote Link to comment https://forums.phpfreaks.com/topic/272241-test-all-characters-in-a-string/ Share on other sites More sharing options...
The Little Guy Posted December 20, 2012 Author Share Posted December 20, 2012 I think I got it! Here is the code I came up with (suggestions?): preg_match("/^[\p{Latin}\p{Nd}\p{Common}]*$/u", $str); Quote Link to comment https://forums.phpfreaks.com/topic/272241-test-all-characters-in-a-string/#findComment-1400677 Share on other sites More sharing options...
requinix Posted December 21, 2012 Share Posted December 21, 2012 Since \p{Common} includes "[characters] that are not part of an identified script" you probably don't want to include that. Otherwise, unless you really want Unicode, [a-z0-9]/i could be just fine. Quote Link to comment https://forums.phpfreaks.com/topic/272241-test-all-characters-in-a-string/#findComment-1400688 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.