Posted By

ashworthconsulting on 01/18/11


Tagged


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

Some0ne
silverskymedia
pytheas
metthyn
mgerdt
voove
jbyerson
ringo380


Getting the domain name out of a URL


 / Published in: PHP
 

  1. <?php
  2. // get host name from URL
  3. preg_match('@^(?:http://)?([^/]+)@i',
  4. "http://www.php.net/index.html", $matches);
  5. $host = $matches[1];
  6.  
  7. // get last two segments of host name
  8. preg_match('/[^.]+\.[^.]+$/', $host, $matches);
  9. echo "domain name is: {$matches[0]}\n";
  10. ?>

Report this snippet  

You need to login to post a comment.