Php Code To Remove Http Www

Php Code To Remove Http Www

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

Here is what I need it to do. The $domain is pulled from the database on the host site it could be or or even and maybe even sometimes

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 ( remove the http://www and compare it to the $siteurls stored in the database which would be, 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 *