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

WBOY
Release: 2016-07-25 08:54:19
Original
1534 people have browsed it
  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.



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!