- preg_replace_callback: documentation ( source)
- print_r: documentation ( source)
- trim: documentation ( source)
<?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;