如何仅从PHP字符串中提取出中文字符?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1765个文字,预计阅读时间需要8分钟。
两种方法:
1.使用preg_match_all配合正则过滤字符串,语法:preg_match_all(/[\x{4e00}-\x{9fff}]+/u, $str, $arr);
2.使用preg_replace配合正则搜索并替换非中文词汇,语法:preg_replace('/[^\x{4e00}-\x{9fff}]/u', '', $str);
两种方法:1、用preg_match_all()配合正则过滤字符串,语法“preg_match_all("/[\x{4e00}-\x{9fff}]+/u","$str",$arr);”;2、用preg_replace()配合正则搜索字符串中的非中文字母,并将其替换成空字符,语法“preg_replace("/[^\x{4E00}-\x{9FFF}]+/u",'',$str)”。
本文共计1765个文字,预计阅读时间需要8分钟。
两种方法:
1.使用preg_match_all配合正则过滤字符串,语法:preg_match_all(/[\x{4e00}-\x{9fff}]+/u, $str, $arr);
2.使用preg_replace配合正则搜索并替换非中文词汇,语法:preg_replace('/[^\x{4e00}-\x{9fff}]/u', '', $str);
两种方法:1、用preg_match_all()配合正则过滤字符串,语法“preg_match_all("/[\x{4e00}-\x{9fff}]+/u","$str",$arr);”;2、用preg_replace()配合正则搜索字符串中的非中文字母,并将其替换成空字符,语法“preg_replace("/[^\x{4E00}-\x{9FFF}]+/u",'',$str)”。

