douqu8828 2010-11-28 04:36
浏览 39
已采纳

序列号检查器

I am trying to create a serial number checker.

Serial Numbers are in ranges
A87594 - A92778
AB34534 - AC23405
B23933 - C344444

I was able to get the numbers to work using range() for the first serial number example, I'm guessing I need to use explode() but I wasn't sure how to explode the letters into a variable and the numbers into a seperate variable.

if($_POST['submit']) {

    $snum = $_POST['serial_number'];

    // 1952
    $jan01_jan07 = range(87594, 92478);

    if (in_array($snum, $jan01_jan07)) {
        echo 'You have a 1952 Widget';
    }
    else {
        echo 'Your serial number is unknown';
    }
}
  • 写回答

2条回答 默认 最新

  • douren1928 2010-11-28 04:45
    关注

    You can try using strcmp, as it checks two strings, so you can check whether the incoming data is equal to or more than the lower bound and less than or equal to the upper bound, like this:

    $data = $_POST['data']; // change this accordingly
    
    if(strcmp($data, $lowerBound) >= 0 && strcmp($data, $upperBound) <= 0) {
        // successful match
    }
    

    As strcmp returns -1, 0, 1 if $data is before, the same as and after $lowerBound (dictionary ordered), so this works for strings as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能