- str_replace: documentation ( source)
- explode: documentation ( source)
- array_pop: documentation ( source)
<?php
$domains = explode(".",str_replace("example.com","","test.example.com"));
print "Test: " . $domains[0] . "<br>";
$target = array_pop($domains);
print "Target: " . $target . "<br>";