Please i have the following function for a contact form, but it shows the following error "Fatal error: Call to undefined function: stripos() in" 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;
}
as you can see from the documentation , stripos()
only exists in PHP5. Anyways, your code doesn't need to chack case-insensitive because it only checks for . @ / : , ;
. @ / : , ;
- so you can just replace stripos()
with strpos()
.
you could also add an own stripos()
to your codebase, wich could look like thoe following (using strtolower()
and function_exists()
):
if(!function_exists("stripos")){
function stripos($haystack, $needle, $offset = 0){
return strpos(strtolower($haystack), strtolower($needle), $offset)
}
}
note that this is a very basic replacemend and might not give the same result like a real stripos()
in each end every case. it's valid for basic usage, but i havn't done broad tests.
stripos是PHP 5的功能,需要升级。
stripos() is not available in PHP 4
stripos
(PHP 5)
stripos — Find the position of the first occurrence of a case-insensitive substring in a string
one of the comments in the manual shows this code, which might help you out:
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 */
As mentioned it's PHP5 only...
But that is a nasty email validation function, try this!
function validateEmail($email)
{
return(preg_match("/^([a-zA-Z0-9_\.\-+])+\@([a-zA-Z0-9\-])+(\.[a-zA-Z0-9]{2,7})+$/", $email));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.