I need to grab the domain without any subdomains from a user inputed email address. For example:
myname@domain.com = domain.com
myname@domain.co.uk = domain.co.uk
^ Those are easy because I can just take whatever comes after the @ sign. The problem comes in with sub domains…
myname@sub1.domain.edu = domain.edu
myname@sub1.sub2.domain.co.uk = domain.co.uk
When I was in the planning stages for this, I thought it would be easy and could just be handled with an explode(), but, I don’t think it can… Here is my attempt:
$_POST['email'] = trim($_POST['email']);
$EmailExplodeAt = explode("@",$_POST['email'], 2);
$EmailExplodeDomains = explode(".",$EmailExplodeAt);
//can't figure out how to grab the domain and TLD only
I’m not sure if this can be done with just PHP or if it requires a regex. I’d prefer to do it with PHP only, simply because I don’t know how to write regular expressions yet. I searched Google quite a bit and couldn’t turn up anything. Any ideas?