Home >Backend Development >PHP Tutorial >A small function to determine whether there is a string containing Chinese characters

A small function to determine whether there is a string containing Chinese characters

WBOY
WBOYOriginal
2016-07-25 09:07:061034browse
  1. /*

  2. can be used in user names and other places where Chinese characters are not allowed
  3. */
  4. //--Example
  5. $str = “dd*(*d ”;
  6. if (iscn($str)) {
  7. echo “String including Chinese”;
  8. } else {
  9. echo “String excluding Chinese”;
  10. }

  11. / /--Function

  12. function iscn($str){
  13. if (preg_match("/.*[".chr(0xa1)."-".chr(0xff)."]+.*/", $str)) {
  14. return true;
  15. } else {
  16. return false;
  17. }
  18. }
  19. ?>

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn