请为联系人表单提供以下函数,但它显示以下错误“致命错误:调用未定义的函数: stripos()”中的“how can I fix it
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;
}发布于 2012-06-11 22:00:43
正如您在the documentation中看到的,stripos()只存在于PHP5中。不管怎么说,你的代码不需要区分大小写,因为它只检查. @ / : , ;,所以你可以用strpos()替换stripos()。
您还可以在代码库中添加一个自己的stripos(),如下所示(使用strtolower()和function_exists()):
if(!function_exists("stripos")){
function stripos($haystack, $needle, $offset = 0){
return strpos(strtolower($haystack), strtolower($needle), $offset)
}
}请注意,这是一个非常基本的替代方法,可能在每种情况下都不会给出像真正的stripos()一样的结果。它对基本用法是有效的,但我没有做过广泛的测试。
发布于 2012-06-11 21:57:33
stripos是一个PHP5函数,需要升级。
发布于 2012-06-11 21:58:32
stripos()在PHP 4中不可用
manual
条带
(PHP 5)
stripos -查找字符串中第一个不区分大小写的子字符串的位置
手册中的注释之一显示了这段代码,这可能会对您有所帮助:
if(!function_exists("stripos")){
function stripos( $str, $needle, $offset = 0 ){
return strpos( strtolower( $str ), strtolower( $needle ), $offset );
}/* endfunction stripos */
}/* endfunction exists stripos */
if(!function_exists("strripos")){
function strripos( $haystack, $needle, $offset = 0 ) {
if( !is_string( $needle ) )$needle = chr( intval( $needle ) );
if( $offset < 0 ){
$temp_cut = strrev( substr( $haystack, 0, abs($offset) ) );
}
else{
$temp_cut = strrev( substr( $haystack, 0, max( ( strlen($haystack) - $offset ), 0 ) ) );
}
if( ( $found = stripos( $temp_cut, strrev($needle) ) ) === FALSE )return FALSE;
$pos = ( strlen( $haystack ) - ( $found + $offset + strlen( $needle ) ) );
return $pos;
}/* endfunction strripos */
}/* endfunction exists strripos */ https://stackoverflow.com/questions/10981513
复制相似问题