public static function replace_subdomain($url, $newSubdomain)
    {
        $url = parse_url($url);
        if(substr_count($url['host'], '.') >= 2) {
            $url['host'] = (str_replace(
                substr($url['host'], 0, strpos($url['host'], '.')),
                $newSubdomain,
                $url['host']
            ));
        } else {
            $url['host'] = $newSubdomain.'.'.$url['host'];
        }
        return self::unparse_url($url);
    }
public static function replace_subdomain($url, $newSubdomain)
    {
        $url = parse_url($url);
        if(substr_count($url['host'], '.') >= 2) {
            $url['host'] = (str_replace(
                substr($url['host'], 0, strpos($url['host'], '.')),
                $newSubdomain,
                $url['host']
            ));
        } else {
            $url['host'] = $newSubdomain.'.'.$url['host'];
        }
        return self::unparse_url($url);
    }
public static function replace_subdomain ( $ url , $ newSubdomain ) { $ url = parse_url ( $ url ) ; if ( substr_count ( $ url [ 'host' ] , '.' ) >= 2 ) { $ url [ 'host' ] = ( str_replace ( substr ( $ url [ 'host' ] , 0 , strpos ( $ url [ 'host' ] , '.' ) ) , $ newSubdomain , $ url [ 'host' ] ) ) ; } else { $ url [ 'host' ] = $ newSubdomain . '.' . $ url [ 'host' ] ; } return self :: unparse_url ( $ url ) ; }
Replaces the subdomain of given url or adds it.

@access public
@param  string $url
@param  string $newSubdomain
@return string
Replaces the subdomain of given url or adds it .