时间:2021-07-01 10:21:17 帮助过:23人阅读
我的思路,
第一步,explode("TK",$str)
第二步,对于第一步的结果进行遍历判断,strstr($explode,"PC"),strstr($explode,"MR")
第三步,将第二步的符合条件的结果进行截取,substr($substr,2,5)
嗯.....
好像有点累赘了,让高手来解决吧.....
$s = '我是一个人TKPC11090987是你TKPC10090987吗?TKPC10098M9Y到底是谁呢?TKMR120990U9TKMR10059E56TKMR10059E56...................................等等等.......';preg_match_all('/(TK[PCMR]{2})(\d{5})\w{3}/', $s, $m);$d = array( 'TKPC' => 11069, 'TKMR' => 10999,);foreach($m[1] as $k=>$v) { if($m[2][$k] <= $d[$v]) { $s = str_replace($m[0][$k], "{$m[0][$k]}", $s); $r[] = $m[0][$k]; }}echo $s;
print_r($r);
Array( [0] => TKPC10090987 [1] => TKPC10098M9Y [2] => TKMR10059E56 [3] => TKMR10059E56)
$str='我是一个人TKPC11090987是你TKPC10090987吗?TKPC10098M9Y到底是谁呢?TKMR120990U9TKMR10059E56TKMR10059E56...................................等等等.................................................';$str=preg_replace('/(TKPC|TKMR)(\d{5})(.{3})/e',"(('$1'=='TKPC' and $2<=11069) or ('$1'=='TKMR' and $2<=10999))?'$1$2$3':'$0'",$str);echo $str;