首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >php4中的Stripos问题

php4中的Stripos问题
EN

Stack Overflow用户
提问于 2012-06-11 21:54:59
回答 4查看 1.3K关注 0票数 0

请为联系人表单提供以下函数,但它显示以下错误“致命错误:调用未定义的函数: stripos()”中的“how can I fix it

代码语言:javascript
复制
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;    
                }
EN

回答 4

Stack Overflow用户

发布于 2012-06-11 22:00:43

正如您在the documentation中看到的,stripos()只存在于PHP5中。不管怎么说,你的代码不需要区分大小写,因为它只检查. @ / : , ;,所以你可以用strpos()替换stripos()

您还可以在代码库中添加一个自己的stripos(),如下所示(使用strtolower()function_exists()):

代码语言:javascript
复制
if(!function_exists("stripos")){
  function stripos($haystack, $needle, $offset = 0){
    return strpos(strtolower($haystack), strtolower($needle), $offset)
  }
}

请注意,这是一个非常基本的替代方法,可能在每种情况下都不会给出像真正的stripos()一样的结果。它对基本用法是有效的,但我没有做过广泛的测试。

票数 3
EN

Stack Overflow用户

发布于 2012-06-11 21:57:33

stripos是一个PHP5函数,需要升级。

票数 0
EN

Stack Overflow用户

发布于 2012-06-11 21:58:32

stripos()在PHP 4中不可用

manual

条带

(PHP 5)

stripos -查找字符串中第一个不区分大小写的子字符串的位置

手册中的注释之一显示了这段代码,这可能会对您有所帮助:

代码语言:javascript
复制
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 */ 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10981513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档