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
Post a Comment