<?php //正则表达式 //定界符:斜杠:/正则/ //匹配开始:^ //匹配结束:$ /*d代表一个数字 w代表一个单词 */ $zz = "/(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])d{8}/"; //$zz = "/w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*/"; $str = "hello 18653378660 21131@qq.com world 15165339515 aaa bbb"; //echo preg_replace($zz,"phone",$str);//根据正则表达式替换字符串 //var_dump(preg_split($zz,$str));//根据正则拆分字符串 /*$arr = array( "18653378660", "hello", "15165339515", "wo" );*/ //preg_match($zz,$str,$arr);//获取满足正则的第一个字符串 //preg_match_all($zz,$str,$arr);//获取满足正则的所有字符串 //$arr = preg_grep($zz,$arr);//匹配数组 var_dump($arr); ?>