时间:2021-07-01 10:21:17 帮助过:22人阅读
$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;