I finally understand what you're asking. Weedpacket's suggestion is exactly what you need. Here's the implementation if you're too lazy:
$url = 'http://something.mypage.com/blah';
$url_components = parse_url($url);
$host_components = explode('.', $url_components['host']);
$result = $host_components[0];
echo $result;
And yeah, your syntax is correct if you want to output it again for some reason:
echo 'http://' . $result . '.mypage.com/blah';