How to use php to match Chinese characters and numbers

墨辰丷
Release: 2023-03-30 17:12:02
Original
1163 people have browsed it

This article mainly introduces the method of operating Chinese and number matching in PHP. Interested friends can refer to it. I hope it will be helpful to everyone.

The specific implementation method is as follows:

function getChinese($string,$encode="GBK") { switch($encode){ case "GBK" :$codelength=2;break; case "GB2312" :$codelength=3;break; case "UTF-8" :$codelength=3;break; case "UTF-16" :$codelength=4;break; } $tmpstr = ''; $arr = array(1,2,3,4,5,6,7,8,9,0); $strlen = strlen($string); for($i=0; $i<$strlen; $i++) { $str=substr($string, $i, 1); $str1=trim($str); if( ord($str)>0xA0 ){ $tmpstr.= substr($string, $i, $codelength); $i = $i+$codelength-1; } } return $tmpstr; }
Copy after login

Summary: The above is the entire content of this article, I hope it can be helpful to everyone’s study .

Related recommendations:

The function of using curl to forge IP in PHP

php uses the MagickWand module to manipulate images Method of adding watermark

PHP simulates the method of response class in asp

The above is the detailed content of How to use php to match Chinese characters and numbers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
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!