3v4l.org

run code in 300+ PHP versions simultaneously
<?php $url = "http://myvcilocal.com"; $subdomain="test"; if(trim($subdomain) == '') { return $url; } $new = preg_replace_callback("~^(http://)?(([^.]+)\.)?([^.]+)\.([a-zA-Z0-9]+)(?=/|$)~",function($matches) use ($subdomain) { $matches[3] = $subdomain; print_r($matches); return $matches[3] = $subdomain; },$url); echo $new."\n".$url;

preferences:
57.51 ms | 402 KiB | 5 Q