Unstoppable Domains

Parsing Current URL for Base Name-PHP

Spacemail by SpaceshipSpacemail by Spaceship
Watch

cornella

New Member
Impact
0
What I need to do is have a little php script "read" the current URL and parse out the base domain name (without tld) so I can use this in a page or article as a variable. For example, if the url is www.domain1.US/articles/vehicles/trucks.htm the script will find "domain1."

What would be even better is if the script could read the current page URL, parse out the base name, compare it to a mysql table and automatically return another field

domain1 | cars
domain2 | trucks
domain3 | motorcycles

Would this be possible? I would appreciate any insight.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
hmm. Sounds a little vague. Is this PHP script going to be embedded in the page? Or will you be using something such as cURL to view the page and grab said information?

If it's embedded you could do a simple stripping of everything between www. and .extension or what have you.

If it's the cURL way, it's still possible just a little more complicated.

-RageD
 
0
•••
Ok,

So if I read this right you want to get just domain out of www.domain.com

So this should work

Code:
$domainparts = explode('.',$_SERVER['HTTP_HOST']);
if (count($domainparts) == 2) echo $domainparts[0];
else echo $domainparts[1];

And also, if I read right, i'm not sure how you want to get cars, trucks, etc. but if you want to pull that from the file name like trucks.html would be trucks, you could use the following code.

Code:
list($file,$ext) = explode('.',str_replace('/','',$_SERVER['SCRIPT_NAME']));
echo $file;

So in the case of www.domain1.US/articles/vehicles/trucks.htm


Code:
$domainparts = explode('.',$_SERVER['HTTP_HOST']);
list($file,$ext) = explode('.',str_replace('/','',$_SERVER['SCRIPT_NAME']));
if (count($domainparts) == 2) echo $domainparts[0];
else echo $domainparts[1];
echo " | $file";

This would give you: domain1 | trucks

Hope this helps answer your questions
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back