3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function set_url_scheme( $url ) { return str_replace('http:', 'https:', $url); } function get_home_url() { return 'https://some.sub.domain.com/foo'; } function multisite_url( $url ) { $stage_url = parse_url( $url ) ?: []; $current_site = parse_url( get_home_url() ) ?: []; $result = ''; empty ( $current_site[ 'user' ] ) or $result .= $current_site[ 'user' ]; empty ( $current_site[ 'pass' ] ) or $result .= ":{$current_site['pass']}"; $result and $result .= '@'; empty ( $current_site[ 'host' ] ) or $result .= "{$current_site['host']}"; empty ( $current_site[ 'port' ] ) or $result .= ":{$current_site['port']}"; empty ( $current_site[ 'path' ] ) or $result .= rtrim( "/{$current_site['path']}", '/' ); empty ( $stage_url[ 'path' ] ) or $result .= "/{$current_site['path']}"; empty ( $stage_url[ 'query' ] ) or $result .= "?{$current_site['query']}"; empty ( $stage_url[ 'fragment' ] ) or $result .= "#{$current_site['fragment']}"; return empty ( $current_site[ 'scheme' ] ) ? set_url_scheme( $result ) : "{$current_site[ 'scheme' ]}://{$result}"; } var_dump( multisite_url('https://maindomain.com') );
Output for 5.6.30, hhvm-3.15.4 - 3.22.0, 7.0.0 - 7.3.0rc3
string(32) "https://some.sub.domain.com//foo"