final public static function replaceAllDotsExceptLastTwo(string $string): string
    {
        $countDots = substr_count($string, '.');
        if ($countDots > 2) {
            $stringArray = explode('.', $string);
            $string = '';
            for ($i = 0; $i < $countDots - 2; ++$i) {
                $string .= $stringArray[$i].'_';
            }
            $string .= $stringArray[$countDots - 2].'.'.$stringArray[$countDots - 1].'.'.$stringArray[$countDots];
        }

        return $string;
    }
final public static function replaceAllDotsExceptLastTwo(string $string): string
    {
        $countDots = substr_count($string, '.');
        if ($countDots > 2) {
            $stringArray = explode('.', $string);
            $string = '';
            for ($i = 0; $i < $countDots - 2; ++$i) {
                $string .= $stringArray[$i].'_';
            }
            $string .= $stringArray[$countDots - 2].'.'.$stringArray[$countDots - 1].'.'.$stringArray[$countDots];
        }

        return $string;
    }
final public static function replaceAllDotsExceptLastTwo ( string $ string ) : string { $ countDots = substr_count ( $ string , '.' ) ; if ( $ countDots > 2 ) { $ stringArray = explode ( '.' , $ string ) ; $ string = '' ; for ( $ i = 0 ; $ i < $ countDots - 2 ; ++ $ i ) { $ string .= $ stringArray [ $ i ] . '_' ; } $ string .= $ stringArray [ $ countDots - 2 ] . '.' . $ stringArray [ $ countDots - 1 ] . '.' . $ stringArray [ $ countDots ] ; } return $ string ; }
Will convert "object.something.cool.today" TO "object_something.cool.today".
Will convert "object.something.cool" TO "object.something.cool".
Will convert "object.something" TO "object.something".
Will convert "object" TO "object".

@param string $string

@return string
Will convert object . something . cool . today TO object_something . cool . today . Will convert object . something . cool TO object . something . cool . Will convert object . something TO object . something . Will convert object TO object .