- var_dump: documentation ( source)
- preg_match: documentation ( source)
<?php
$main_url_host = 'main.example.com';
$current_url_host = 'sub.main.example.com';
preg_match('~(.+)*\.' . $main_url_host. '~', $current_url_host, $matches );
var_dump($matches[1]);