PHP正则表达式只提取中文或者英文的方法
针对杂乱内容,可以自定义函数,通过正则表达式的方式只提取中文或者只提取英文。
针对杂乱内容,可以自定义函数,通过正则表达式的方式只提取中文或者只提取英文。
具体方法
function get_cn($name){//只提取中文 preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $name, $content); $string = implode('',$content[0]); echo $string; } function get_en($name){//只提取英文 preg_match_all('/[a-zA-Z]+/', $name, $content); $string = implode('',$content[0]); echo $string; }
本文属原创,转载请注明原文:https://www.zhimatong.com/jiaocheng/895.html
为保证教程的实用性及扩大知识面覆盖,如果您有相似问题而未解决,可联系在线客服免费技术支持。
点赞 1
热门主题
相关阅读
- PHP常用的获取网页html内容的6种方法
- ThinkPHP使用update函数更新数据的方法
- PHP 将数组打乱 shuffle 函数
- PHP 对数组使用 自然算法 进行排序 natsort 与 natcasesort 函数
- PHP 字符串替换 substr_replace 与 str_replace 函数
- PHP 字符串输出 echo、print 与 printf 函数
- PHP 字符串获取 substr 与 strstr 函数
- PHP 字符串计算 strlen、strpos 与 strrpos 函数
- PHP 字符串存储(转义) addslashes 与 stripslashes 函数
- PHP 字符串去除 trim、ltrim 与 rtrim 函数
- PHP 数组排序 sort、asort 及 ksort 系列函数
- PHP 字符串 XHTML格式化显示 nl2br 与 htmlspecialchars 函数