此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【zzxap】截止到2008-07-04 12:04:48的历史汇总数据(不包括此帖):
发帖的总数量:68                       发帖的总分数:2460                     
结贴的总数量:59                       结贴的总分数:2107                     
无满意结贴数:7                        无满意结贴分:250                      
未结的帖子数:9                        未结的总分数:353                      
结贴的百分比:86.76 %               结分的百分比:85.65 %                  
无满意结贴率:11.86 %               无满意结分率:11.87 %                  
楼主加油

解决方案 »

  1.   

    你这样判断细路也不错,但如果写成一句会不会后期维护不方便,代码我个人认为还是越简单越好,如果写成一句的话如下:$str1 = '<div id="error"onmousedown="StartMove(event)" onmouseup="StopMove(event)" >'.'<div ><input type="button"  value="关闭" id="button" onclick="closeWin()"  ></div>' . '<span >请输入18位身份证号码,请重新填写!</span>'.'</div>';
    $str2='<div id="error" onmousedown="StartMove(event)" onmouseup="StopMove(event)">'.'<div><input type="button"   value="关闭" id="button" onclick="closeWin()"  ></div>'.substr($body,0,2) . "此地区代码不存在".'</div>';
    $str3='<div id="error" onmousedown="StartMove(event)" onmouseup="StopMove(event)">'.'<div><input type="button" value="关闭" id="button" onclick="closeWin()"  ></div>' .substr($body,6,8). "出生年月不符合规则".'</div>';
    $str4 = '<div id="error" onmousedown="StartMove(event)" onmouseup="StopMove(event)">'.'<div><input type="button" value="关闭" id="button" onclick="closeWin()"  ></div>' . "前17位必?為數字".'</div>';这是你要输入的四句话,太长我在些就用变量代替,如果你要用一句的话,把上面四个变量代入下式即可:
    echo strlen($body)!=18?$str1:($province_code[substr($body,0,2).'0000']==''?$str2:(!preg_match("/^(18||19||20)[0-9][0-9](0[1-9])|(1[1-2])[0-3][0-9]$/",substr($body,6,8))?$str3:(!is_numeric(substr(trim($_POST['aa']),0,17))?$str4:'所有判断都正确')))三目套三目,不知道可行,没试过,有问题再说出来大家讨论
      

  2.   

    $str1 = ' <div id="error"onmousedown="StartMove(event)" onmouseup="StopMove(event)" >'.' <div > <input type="button"  value="关闭" id="button" onclick="closeWin()"  > </div>' . ' <span >请输入18位身份证号码,请重新填写! </span>'.' </div>'; 
    $str2=' <div id="error" onmousedown="StartMove(event)" onmouseup="StopMove(event)">'.' <div> <input type="button"  value="关闭" id="button" onclick="closeWin()"  > </div>'.substr($body,0,2) . "此地区代码不存在".' </div>'; 
    $str3=' <div id="error" onmousedown="StartMove(event)" onmouseup="StopMove(event)">'.' <div> <input type="button" value="关闭" id="button" onclick="closeWin()"  > </div>' .substr($body,6,8). "出生年月不符合规则".' </div>'; 
    $str4 = ' <div id="error" onmousedown="StartMove(event)" onmouseup="StopMove(event)">'.' <div> <input type="button" value="关闭" id="button" onclick="closeWin()"  > </div>' . "前17位必?為數字".' </div>'; $str=$str1+$str2+$str3+$str4echo $str
    这样不行?
      

  3.   

    还是那么多代码啊。我只想要一个DIV。多个字符在div内显示
      

  4.   

    我想知道楼主想解决什么问题,为什么一定要在一个echo输出!
      

  5.   

    晕,理解错了,看这样可行;if (strlen($body)<18||strlen($body)>18){
    $msg .= '请输入18位身份证号码,请重新填写!<br>';
    }
    else  if ($province_code[substr($body,0,2).'0000']=='')
           {    //判断它是否在数组$city_code内
    $msg .= substr($body,0,2).'此地区代码不存在<br>';
       }
    else if (!preg_match("/^(18||19||20)[0-9][0-9](0[1-9])|(1[1-2])[0-3][0-9]$/",substr($body,6,8))) 
        {
    $msg .= substr($body,6,8).'出生年月不符合规则<br>';
        }   else if (!is_numeric(substr(trim($_POST['aa']),0,17)))
    {
    $msg .= '前17位必?為數字<br>';
    }echo '<div id="error"onmousedown="StartMove(event)" onmouseup="StopMove(event)" >'.'<div ><input type="button"  value="关闭" id="button" onclick="closeWin()"  ></div>' . '<span >'.$msg.'</span>'.'</div>';
    每输出一个错误就有会换个行
    应该可以的吧
      

  6.   

    而且所有输出都在一个DIV里面,
      

  7.   

    echo 只能用在一个循环体内,不能用于多个else if之间。
      

  8.   

    echo和所有的if必须位于同一个{}内才能显示$msg吧
      

  9.   

    一直没有搞懂为什么
    strlen($body) <18 ||strlen($body)>18
    不写成strlen($body) != 18
      

  10.   

    switch(1) {
    case strlen($body)<18||strlen($body)>18) :
    $message = '请输入18位身份证号码,请重新填写!';
    break;
    case $province_code[substr($body,0,2).'0000']=='' :
    $message = substr($body,0,2) . "此地区代码不存在";
    break;
    case !preg_match("/^(18||19||20)[0-9][0-9](0[1-9])|(1[1-2])[0-3][0-9]$/",substr($body,6,8))) :
    $mssage = substr($body,6,8). "出生年月不符合规则";
    break;
            case !is_numeric(substr(trim($_POST['aa']),0,17))) :
    $message = "前17位必?為數字";
    break;
    }echo '<div id="error"onmousedown="StartMove(event)" onmouseup="StopMove(event)" >'.'<div ><input type="button"  value="关闭" id="button" onclick="closeWin()"  ></div>' . $message .'</div>';
      

  11.   

    楼上的根我的方法其实是换汤不换药,只是你写成switch形式,而我没有改变他的判断方式
    而楼上的方法有个问题,如果用户有多个错误,那你只能提示第一个判断到的错误,不能提示所有错误,应该把$message连起来,
      

  12.   


    从楼主代码实现看,本身就只提示遇到的第一个错误,而不是提示所有错误,不要理所当然的去认为
    <?php
    //引用唠叨老大的代码
    //如楼主需要提示所有错误把123所在的break注释掉即可
    $message = '';
    switch(1){
        case 18 != strlen($body):
          $message .= '请输入18位身份证号码,请重新填写!';
        break;//1    case ''==$province_code[substr($body,0,2).'0000']:
          $message .= substr($body,0,2) . '此地区代码不存'; 
        break;//2    case !preg_match("/^(18||19||20)[0-9][0-9](0[1-9])|(1[1-2])[0-3][0-9]$/",substr($body,6,8))) :
          $mssage .= substr($body,6,8) . '出生年月不符合规则';
        break;//3    case !is_numeric(substr(trim($_POST['aa']),0,17))):
          $message .= '前17位必?為數字';
        break;//4
    }echo '<div id="error"onmousedown="StartMove(event)" onmouseup="StopMove(event)">' . 
         '<div><input type="button" value="关闭" id="button" onclick="closeWin()"></div>' . 
         '<div><span>'.$message .'</span></div>';
    ?>
      

  13.   

    $errMsg = '';if (第一个错误) 
    $errMsg .= '错误1';if (第二个错误) 
    $errMsg .= '错误2';
    if (!empty($errMsg)) {
    发生错误了
    }
      

  14.   

    标准的switch结构
    switch(键表达式) {
      case 键值1:
        ....
        break;
      ....
      case 键值n:
        ....
        break;
      default:
        ....
    }php对这个结构进行了扩展--在case分支上可以使用表达式对于你的情况,键表达式已经不起主要作用了,所以可任意指定
      

  15.   

    好像运行不了switch里面的代码。
    是不是要先if (){switch}  else {switch} 才可以执行switch里面的代码?如果如果switch前面没有if,感觉不会执行switch里面的代码,直接跳到switch后面执行。
      

  16.   

    第一楼的代码,把else去掉,错误提示写进$error[]里面
    最后 如果count($error)>0 就echo '<div>',join('<br>',$error),'</div>';
      

  17.   

    要怎样才能执行switch里面的代码啊?执行不了,直接跳过了
      

  18.   

    个人认为运用if会比较好
    因为if是执行效率相对提高,而且也日后也可以随时可以增减错误判断
    如果把所有在switch里的break;拿掉的话,不如直接用if,还要来得更简单。//初始化变数
    $ErrMsg = (string)''; //存取错误的变数
    $iPos = (int)0; //存取错误的顺序//检查长度
    $iPos++;
    if (strlen($body)!=18)
        $ErrMsg .= "{$iPos}. 请输入18位身份证号码,请重新填写!\n";//检查地区代码是否存在
    $iPos++;
    if ($province_code[substr($body,0,2).'0000']=='') 
        $ErrMsg .= "{$iPos}. ".substr($body,0,2)."此地区代码不存在\n"; //检查出生年月规则
    $iPos++;
    if (!preg_match("/^(18||19||20)[0-9][0-9](0[1-9])|(1[1-2])[0-3][0-9]$/",substr($body,6,8))) 
        $ErrMsg .= "{$iPos}. ".substr($body,6,8). "出生年月不符合规则\n";//检查输入值是否符合
    $iPos++;
    if (!is_numeric(substr(trim($_POST['aa']),0,17)))
        $ErrMsg .= "{$iPos}. 前17位必?為數字\n";if (!empty($ErrMsg)) 
        echo "
        <div id="error"onmousedown=\"StartMove(event)\" onmouseup=\"StopMove(event)\">
            <div><input type=\"button\" value=\"关闭\" id=\"button\" onclick=\"closeWin()\"></div>
            <span>".nl2br($ErrMsg)."</span>
        </div>";在每次的错误检查返回的结果存入变数,每次存入时都加上\n新行符,在echo 错误时,加上n12br这个涵式就可以让网页自动换行了
    错误判断也可以随时加入或减少,也非常方便日后处理,代码处理也很清楚哦以上是个人认为的啦