PHP determines Chinese and English characters (one more)

WBOY
Release: 2016-07-25 09:11:02
Original
1018 people have browsed it
I seem to remember that I posted one before, written by myself. Today’s one is online and comes from: http://www.cnblogs.com/zcy_soft/archive/2010/12/13/1904791.html
  1. /* There is actually a lot of knowledge involved in judging Chinese. The underlying internal encoding involves various differences in utf-8, gbk, and gb13800. I once studied the problem of how to distinguish what character a character is. There are too many related details.
  2. Today I made a PHP code to determine Chinese. I hope it can be helpful to friends who are studying Chinese judgment. */
  3. New Document
  4. < ;META http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. $str = "China";
  6. echo $str;
  7. echo "
    ";
  8. //if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str) ) { //Can only be used under GB2312
  9. if (preg_match("/^[x7f-xff]+$/", $str)) { //Compatible with gb2312, utf-8
  10. echo "Correct input";
  11. } else {
  12. echo "Wrong input";
  13. }
  14. ?>
  15. /*
  16. Encoding table
  17. Double-byte character encoding range
  18. 1. GBK (GB2312/GB18030)
  19. x00-xff GBK double-byte encoding range
  20. x20-x7f ASCII
  21. xa1-xff Chinese gb2312
  22. x80-xff Chinese gbk
  23. 2. UTF-8 (Unicode)
  24. u4e00-u9fa5 (Chinese)
  25. x3130-x318F (Korean
  26. xAC00-xD7A3 (Korean)
  27. u0800-u4e00 (Japanese)*/
Copy code


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template