shortysbest Posted December 9, 2010 Share Posted December 9, 2010 I'm pretty new to this, How exactly could i get the text between the www. and .com? so if i have a url: http://www.facebook.com I want to just return "facebook" Quote Link to comment Share on other sites More sharing options...
eo92866 Posted December 10, 2010 Share Posted December 10, 2010 the below code and many more examples that may or may not fit your needs are at http://www.php.net/manual/en/function.preg-match.php Example #3 Getting the domain name out of a URL <?php // get host name from URL preg_match('@^(?:http://)?([^/]+)@i', "http://www.php.net/index.html", $matches); $host = $matches[1]; // get last two segments of host name preg_match('/[^.]+\.[^.]+$/', $host, $matches); echo "domain name is: {$matches[0]}\n"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.