符合条件的字符串用红色显示

WBOY
Release: 2016-06-23 13:37:36
Original
1597 people have browsed it

字符串:
我是一个人TKPC11090987是你TKPC10090987吗?TKPC10098M9Y到底是谁呢?TKMR120990U9TKMR10059E56TKMR10059E56...................................等等等.................................................

要求:
1、截取每一个TKPC和TKMR后的连续5位数。(例中的截取出来就应该是TKPC有11090,12098,TKMR有12099,11059等)
2、将截取后的数字按照如下条件对比:
      2.1   TKPC的两组数字,如果有小于等于11069的话, 用红色在原字符串中显示满足条件的每组TKPC+后8位。
      2.1   TKMR的两组数字,如果有小于等于10999的话, 用红色在原字符串中显示满足条件的每组TKMR+后8位。


回复讨论(解决方案)

$s = '我是一个人TKPC11090987是你TKPC10090987吗?TKPC10098M9Y到底是谁呢?TKMR120990U9TKMR10059E56TKMR10059E56..';$d = array(  'TKPC' => '11069',  'TKMR' => '10999',);echo preg_replace_callback('/(TKPC|TKMR)(\d{5}).{3}/', function($m) use ($d) {  if($m[2] <= $d[$m[1]]) return "$m[0]";  return $m[0];  }, $s);
Copy after login
我是一个人TKPC11090987是你TKPC10090987吗?TKPC10098M9Y到底是谁呢?TKMR120990U9TKMR10059E56TKMR10059E56..

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!