Home  >  Article  >  Backend Development  >  PHP determines whether a string is all Chinese or contains Chinese characters

PHP determines whether a string is all Chinese or contains Chinese characters

WBOY
WBOYOriginal
2016-07-25 08:54:191557browse
  1. $str="'324 is";
  2. if(!eregi("[^x80-xff]","$str")){
  3. echo "All in Chinese";
  4. }else{
  5. echo "not";
  6. }
Copy code

2, determine if it contains Chinese

  1. $str = "Chinese";
  2. if (preg_match("/[x7f-xff]/", $str)) {
  3. echo "Contains Chinese";
  4. }else{
  5. echo "No Chinese";
  6. }
  7. or
  8. $pattern = '/[^x00-x80]/';
  9. if(preg_match($pattern,$str)){
  10. echo "Contains Chinese";
  11. }else{
  12. echo "No Chinese";
  13. }
Copy code

Instructions: The above code was tested under utf-8 and has not been tested under other encodings.



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