3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $current_url = 'current.sub.meh.com'; $stage_url = 'foo.stage.it'; $current_domains = explode( '.', $current_url ); $current_sub_domain = array_slice( $current_domains, 0, count( $current_domains ) - 2 ); $stage_top_domain = array_slice( explode( '.', $stage_url ), - 2, 2 ); $stage_url = implode( '.', array_merge( $current_sub_domain, $stage_top_domain ) ); echo $stage_url;
Output for 5.6.30, hhvm-3.15.4 - 3.22.0, 7.0.0 - 7.2.9
current.sub.stage.it