/*
* 正则表达式匹配
*/
$email = '137813369@qq.com';
$regex = '/\w+([−+.]\w+)*@\w+([−.]\w+)*\.\w+([−.]\w+)*/'; 
if (preg_match($regex, $email)) {
    echo('匹配');
}else {
    echo('不匹配');
}

$url = 'http://www.cnblogs.com/hellohell/p/5718319.html';
$regex = '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?/'; 

$regex = '/^http(s?):\/\/[\w]+\.[\w]+[\S]*/'; 
if (preg_match($regex, $url)) { echo('匹配'); }else { echo('不匹配'); } $phone = '15680888862'; $regex = '/1[3458]\d{9}/'; if (preg_match($regex, $phone)) { echo('匹配'); }else { echo('不匹配'); } /* * 自带函数匹配 */ $email = "lastchiliarch@163.com"; if (filter_var($email, FILTER_VALIDATE_EMAIL)) { echo('匹配'); }else{ echo('不匹配'); } $url = "http://www.cnblogs.com/hellohell/p/5718319.htm"; if (filter_var($url, FILTER_VALIDATE_URL)) { echo('匹配'); }else{ echo('不匹配'); } $ip = "123.54.178.71"; if (filter_var($ip, FILTER_VALIDATE_IP)) { echo('匹配'); }else{ echo('不匹配'); }

 

如果要在文章中搜索匹配结果:

//查询匹配结果
$str = '手机号13712345678';
preg_match_all("/^1[34578]\d{9}$/", $str, $mobiles);
var_dump($mobiles); 

 

相关文章:

  • 2022-02-05
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-08
猜你喜欢
  • 2022-01-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
相关资源
相似解决方案