Php Code To Remove Http Www

Php Code To Remove Http Www
Hello

I have code that works fine when used on a regular domain like test.com but if used on a subdomain like test.test-test.com it is not working, it strips everything but test.com

Here is what I need it to do. The $domain is pulled from the database on the host site it could be http://domain.com or http://www.domain.com or even http://www.test.test-test.com and maybe even sometimes http://www.test-test.com/test

I need to check $domain for the host site against the $siteurl data that is stored in the database, all of the $siteurls are the domain only no http or www.

so what I need it to do is if $domain (http://www.test.test-test.com) remove the http://www and compare it to the $siteurls stored in the database which would be test.test-test.com, if a match then do this action.

Hope I explained that well enough for someone to understand.

Here is the existing code:

$pattern = ‘/\w+\..{2,3}(?:\..{2,3})?(?:$|(?=\/))/i’;
$url = $domain;
if (preg_match($pattern, $url, $domain1) === 1) {

if($domain1[0]==”$siteurl1″) {
$enabled = $sitestatus1;
$site = $site1;
} elseif($domain1[0]==”$siteurl2″) {
$enabled = $sitestatus2;
$site = $site2;
} elseif($domain1[0]==”$siteurl3″) {
$enabled = $sitestatus3;
$site = $site3;
} elseif($domain1[0]==”$siteurl4″) {
$enabled = $sitestatus4;
$site = $site4;
}
} //end prgmatch

Leave a Reply

Your email address will not be published. Required fields are marked *