1)utf-8的编码格式,匹配中文代码如下:
<?php
$str = "utf-8下匹配出中文字符串";
$preg = "/[\x{4e00}-\x{9fa5}]+/u";
if(preg_match_all($preg,$str,$matches)){
print_r($matches);
}
?>
2)gb2312的编码格式,匹配中文字符串代码如下:
<?php
$str = "gb2312下匹配出中文字符串";
$preg = "/([".chr(0xb0)."-".chr(0xf7)."][".chr(0xa1)."-".chr(0xfe)."])+/i";
if(preg_match($preg,$str,$matches)){
print_r($matches);
}
?>
--------------------- 本文来自 a771948524 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/zxlstudio/article/details/26575599?utm_source=copy