Home > Backend Development > PHP Tutorial > Chinese verification function (php javascript)_PHP tutorial

Chinese verification function (php javascript)_PHP tutorial

WBOY
Release: 2016-07-13 10:54:05
Original
862 people have browsed it

Chinese character judgment is based on string encoding, /^[chr(0xa1)-chr(0xff)]+$ This is the PHP verification regular expression to judge whether it is Chinese Let’s look at an example of verifying Chinese characters

Chinese character judgment is based on string encoding, /^[chr(0xa1)-chr(0xff)]+$ This is the PHP tutorial verification regular expression to judge whether it is Chinese
Let’s look at an example of verifying Chinese


$str = "Yiju Tutorial Network";
if (preg_match("/^[".chr(0xa1)."-".chr(0xff)."]+$/", $str)) {
echo "This is a pure Chinese string";
} else {
echo "This is not a pure Chinese string";
}

js

var str = "php programming";
if (/^[u4e00-u9fa5]+$/.test(str)) {
alert("The string is all in Chinese");
} else {
alert("This string is not all in Chinese");
}

php

if($en_utf8)
{ $joid = preg_replace("[^0-9a-za-z_-|x4e00-x9fa5|:|/|#|.]","",$joid); > else
{ $joid = preg_replace("[^0-9a-za-z_-|".chr(0xa1)."-".chr(0xff)."|:|/|#|.]","",$ joid); } //Chinese matching of gb2312

To determine whether a string is Chinese in php, you will follow this idea:

$str = "php programming";
if (preg_match("/^[u4e00-u9fa5]+$/",$str)) {
print("This string is all in Chinese");
} else {
print("This string is not all Chinese");
}
?>

http://www.bkjia.com/PHPjc/632360.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632360.htmlTechArticleChinese character judgment is based on string encoding, /^[chr(0xa1)-chr(0xff)] +$This is the PHP verification regular expression to determine whether it is Chinese. Let’s look at an example of verifying Chinese characters.
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