Skip to Content About Archive Belief Contact Pudding Search


php: domain base regex


Sunday, May 11, 2008

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

I needed to get a domain name with out any subdomains or tld for bacon 100%. after a bit of trail and error

//body of domain ex: iam.bacon.com we want bacon
$domainBody=preg_replace(’/^[a-z0-9.-]*?[.]{0,1}([a-z0-9-]*?)\.[a-z.]{2,6}$/i’,”$1″,$serverHost);

I tested on the following domains locally

www.frameword.sid
framework.sid
am.i.a.sub.domain.y.o.u.b.e.t.framework.sid.me
am.i.a.sub.domain.y.o.u.b.e.t.framework.sid

I’d think it’d be pretty simple to change the regex to get the full domain, just move \.[a-z]{2,6} in to the subsearch - is that even what you call it

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
Might Be Related

Leave a Reply


In order to submit a comment, you need to mention your name and your email address (which won't be published). And ... don't forget your comment!

Comment Form