php - Getting domain part from path -


this question has answer here:

if use __div__ path this:

/home/domaincom/public_html/account/assets 

i need domaincom part only, how do that?

thanks

ironically, there's no 'easy' way $_server alone.

instead, first retrieve path $_server["document_root"] , use explode() on /:

<?php  $url = $_server["document_root"]; //$url = "/home/domaincom/public_html/account/assets"; $parts = explode('/', $url); $domain = $parts[2]; echo $domain; // domaincom 

i've created working example showcasing here.

hope helps! :)


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -