显示符合条件的字段

WBOY
Release: 2016-06-23 13:37:35
Original
1122 people have browsed it

字符串:
TKPC10090987TKPC10098M9YTKMR120990U9TKMR10059E56

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


回复讨论(解决方案)

$str = "TKPC10090987TKPC10098M9YTKMR120990U9TKMR10059E56";for ($i = 0, $len = strlen($str); $i < $len; $i++){    if (substr($str, $i, 4) == 'TKPC'){        if (substr($str, $i+4, 5) <= 11069){            echo 'TKPC' . substr($str, $i+4, 8) . "\n";        }    }    if (substr($str, $i, 4) == 'TKMR'){        if (substr($str, $i+4, 5) <= 10999){            echo 'TKMR' . substr($str, $i+4, 8) . "\n";        }    }}
Copy after login


TKPC10090987TKPC10098M9YTKMR10059E56
Copy after login

Related labels:
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