数组里的前几个数字怎么判断。并给出分值
如果数组是以
800 开头的。。给这个数组500分
80开头的。。  给这个数组50分400 开头的。。给这个数组500分
40 开头的。。给这个数组50分

解决方案 »

  1.   

    $str="80080000";
    $newstr=$str[0].$str[1].$str[2];
    不过,最好用substr来判断。也可以用strpos,先判断长的,比如800,再判断短的,80.
    另外,你的规则设定有问题,80包含了800。
      

  2.   

    $str=要检查的数字串;
    if(preg_match('/^[8][0][0].$/',$str))
    {
        以800开头:给500分;
    }
    if(preg_match('/^[8][0][^0].$/',$str))
    {
        以80开头:给50分;
    }
      

  3.   

    $str="80080000";
    echo preg_replace('/(80+).+/', '$1', $str); //800
    echo preg_replace('/(80+).+/e', 'strlen("$1")', $str); //3$str="801234";
    echo preg_replace('/(80+).+/', '$1', $str); //80
    echo preg_replace('/(80+).+/e', 'strlen("$1")', $str); //2利用 preg_replace('/(80+).+/e', 'strlen("$1")', $str); 的结果,查询分值表即可
      

  4.   

    果断使用strpos函数,什么正则丢一边
      

  5.   

    出错阿~<?php 
    $str='80123';
    if(preg_match('/^[8][0][0].$/',$str))
    {
      echo 500;
    }
    if(preg_match('/^[8][0][^0].$/',$str))
    {
     echo 50;
    ?>
      

  6.   

    用 substr 或 perg_match都可以实现 
      

  7.   

    <?php  
    $str='800123';
    if(ereg("^[8][0][0].",$str))//POSIX 风格
    {
      echo '500';
    }
    if(preg_match('/^[8][0][^0]./',$str))//PCRE风格
    {
     echo '50';
    }
    ?>
    以上可以运行。
      

  8.   


    你说strpos 查找80的时候 800 会怎么样呢? 
      

  9.   

    其实你嫌弃麻烦的话还可以$str = '8001606';if ($str{0} === '8') {
       
    }