im looking for a php script or class in php so that i can split my domain name.

for example, i have this:

$string = www.wallpaperama.com

and i only want

$string = wallpaperama

but i want the script to take into considration other tld like

$string = mail.www.wallpaperama.co.uk

how can i do this?