我有一个反馈的脚本。

时间:2012-04-02 10:06:33

标签: php

我有一个反馈的特定脚本。当我提交表格时,它会显示

” 警告:substr()期望参数2为long,在第26行的/home/jetkvdmn/public_html/genFunctions.php中给出字符串“

以下代码

<?php
$cEpro ="&copy; Redeeming Mission 2012.";

function checkText($ElementVal) {
    // If Text is too short
    if (strlen($ElementVal)< 3) {
        //alert('Text too small');
        return false;
    } else{
        return true;
    }
}


function checkEmail($vEmail) {   
    $invalidChars ="/:,;" ; 
    if(strlen($vEmail)<1) return false;             // Invalid Characters
    $atPos = stripos($vEmail,"@",1);                // First Position of @

    if ($atPos != false) 
        $periodPos = stripos($vEmail,".", $atPos);  //If @ is not Found Null . position

    for ($i=0; $i<strlen($invalidChars); $i++) {    //Check for bad characters 
        $badChar = substr($invalidChars,i,1);       //Pick 1
        if(stripos($vEmail,$badChar,0) != false)    //If Found
            return false;
    }

    if ($atPos == false)                            //If @ is not found
        return false;       
    if ($periodPos == "")                           //If . is Null
        return false;
    if (stripos($vEmail,"@@")!=false)               //If @@ is found
        return false;
    if (stripos($vEmail,"@.") != false)             //@.is found
        return false;
    if (stripos($vEmail,".@") !=  false)            //.@ is found
        return false;

    return true;    
}
?>

2 个答案:

答案 0 :(得分:2)

$badChar = substr($invalidChars,i,1);

应该是

$badChar = substr($invalidChars,$i,1);
                               ^^^

答案 1 :(得分:0)

您正在将i传递给substr函数,而不是$i