CodeIgniter Forums
Getting domain from string - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Getting domain from string (/showthread.php?tid=41768)



Getting domain from string - El Forum - 05-16-2011

[eluser]Jujubins[/eluser]
Theres some function in CI to do that?

Example:
http://images.google.com/search?tbm=isch&hl=pt-BR&source=hp&biw=1366&bih=667&q=test&gbv=2&aq=f&aqi;=&aql;=&oq;=

Return:
google.com


Getting domain from string - El Forum - 05-17-2011

[eluser]Iván Argulo[/eluser]
This will return "images.google.com"

Code:
$url = 'http://images.google.com/q?all_params&and=so&on;';

// Deletes the ugly protocol
$url = str_replace('http://', '', $url);
$url = str_replace('https://', '', $url);
            
$url_a = explode('/', $url);
            
$url_show = $url_a[0];

echo $url_show;

Of course it could be improved, but it's a 1-minute solution.

Hope it helps


Getting domain from string - El Forum - 05-17-2011

[eluser]n0xie[/eluser]
There is parse_url()