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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -