zoukankan      html  css  js  c++  java
  • php正则匹配汉字提取其它信息剔除和验证邮箱

     正则匹配汉字提取其它信息剔除demo

     1 <?php 
     2 //提取字符串中的汉字其余信息剔除
     3 $str='�te,st 测 。试,.,。?!:;·…~&@#,.?!:;、……~&@#“”‘’〝 "〞'´'><﹞﹝><》《】【)(()[] - 1234456789'; 
     4 preg_match_all('/[x{4e00}-x{9fff}]+/u', $str, $matches_one);//只要汉字
     5 preg_match_all('/[a-zA-Z0-9x{4e00}-x{9fff}]+/u', $str, $matches_two);//只保留汉字和数字和英文字符
     6 
     7 $str_one = implode('', $matches_one[0]);
     8 $str_two = implode('', $matches_two[0]);
     9 
    10 echo $str_one;//测试
    11 echo '<br>';
    12 echo $str_two;//test测试1234456789

     

    正则验证邮箱demo

     1 <?php
     2 /**
     3  * verifyEmail
     4  * @param  string $str 邮箱字符串
     5  * @return boolean 
     6  */
     7 header('Content-Type: text/html; charset=utf-8');
     8 function verifyEmail($str){
     9     //$pattern = '/^w[-w.+]*@([A-Za-z0-9][-A-Za-z0-9]+.)+[A-Za-z]{2,14}$/';
    10 
    11     //@前面的字符可以是英文字母和._- ,._-不能放在开头和结尾,且不能连续出现
    12     $pattern = '/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+.[a-z]{2,14}(.[a-z]{2})?)$/i';
    13     if(preg_match($pattern,$str)){
    14         return true;
    15     }else{
    16         return false;
    17     }
    18 }
    19 
    20 //测试验证邮箱函数
    21 $str = 'Te-st._-@test.com';
    22 if(verifyEmail($str)){
    23     echo '电子邮箱格式合法';
    24 }else{
    25     echo '电子邮箱格式不合法';
    26 }

    php 判断web和手机demo

     1 //php 判断web和手机
     2 function is_mobile()
     3 {
     4     $agent = strtolower($_SERVER['HTTP_USER_AGENT']);
     5     $is_pc = (strpos($agent, 'windows nt')) ? true : false;
     6     $is_mac = (strpos($agent, 'mac os')) ? true : false;
     7     $is_iphone = (strpos($agent, 'iphone')) ? true : false;
     8     $is_android = (strpos($agent, 'android')) ? true : false;
     9     $is_ipad = (strpos($agent, 'ipad')) ? true : false;
    10     
    11     if($is_pc){
    12           return  false;
    13     }
    14    
    15     if($is_mac){
    16           return  true;
    17     }
    18     
    19     if($is_iphone){
    20           return  true;
    21     }
    22     
    23     if($is_android){
    24           return  true;
    25     }
    26     
    27     if($is_ipad){
    28           return  true;
    29     }
    30 }
  • 相关阅读:
    idea14导入eclipse项目并部署运行完整步骤
    Java之Socket
    Docker之宿主机ssh至docker容器
    ElasticSearch的安装、使用、踩坑
    Linux下grep、tail、wc、awk文件处理命令
    Spring中@Async注解实现“方法”的异步调用
    Thrift——栗子
    Linux中的守护进程——supervise
    【composer】 PHP composer 镜像地址更换
    【Mac】解决macos安装升级时报错安装所选更新时发生错误的问题
  • 原文地址:https://www.cnblogs.com/cxx8181602/p/10401313.html
Copyright © 2011-2022 走看看