Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to remove www from $_SERVER['HTTP_HOST'] how?

Tags:

php

I need to remove www from the string given by $_SERVER['HTTP_HOST']

How can I do that in PHP?

like image 883
DiegoP. Avatar asked Nov 29 '22 16:11

DiegoP.


2 Answers

$server_name = str_replace("www.", "", $_SERVER['HTTP_HOST']);

That should do the trick...

like image 179
BenGC Avatar answered Dec 10 '22 09:12

BenGC


if (substr($_SERVER['HTTP_HOST'], 0, 4) == 'www.') {
    $domain = substr($_SERVER['HTTP_HOST'], 4);
} else {
    $domain = $_SERVER['HTTP_HOST'];
}
like image 29
Tim Fountain Avatar answered Dec 10 '22 07:12

Tim Fountain