解决方案 »

  1.   

    如果是精确到 关键字 那就直接用替换函数就好了
    str_replace — Replace all occurrences of the search string with the replacement string
      

  2.   

    你可以在分支位置加上echo,看看走了哪条分支再确定问题。if ($pos2) {
        echo 'pos2';
        return $haystack;
    }elseif($pos3){
        echo 'pos3';
        return $haystack;
    }elseif($pos4){
        echo 'pos4';
        return $haystack;
    } elseif($pos === false){
        echo 'pos';
        return '';
    }else{
        echo 'other';    
        return substr_replace($haystack, $replace, $pos, strlen($needle));
    }