Forum Moderators: coopster

Message Too Old, No Replies

printing the current url without the "-"'s and ".com"'s

echo $_SERVER["SERVER_NAME"];

         

GerBot

3:57 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



Hi,
I have this script on my site
echo $_SERVER["SERVER_NAME"];

which produces
www.blue-domain.com

but I want to print

blue domain

any help is greatly appreciated from this non-programmer

Adrian2k4

4:03 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



you could regex it...

...but this could get fishy if it sould be capable of handling all RFC conform URLs:

it wouldn't work with the URL "http://foo.bar.baz.example.com/"

mincklerstraat

4:09 pm on Dec 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Adrian2K4's recommendation (regex) is definitely the pro way to go - you probably want an easier way that you'll be able to customize later.

Maybe something like:


$url = $_SERVER['SERVER_NAME'];
$url = str_replace('www.', '', $url); /* removes the 'www.' */
$url = str_replace('.com', '', $url); /* you'll get the rest */
$url = str_replace('-', ' ', $url);

GerBot

4:23 pm on Dec 12, 2004 (gmt 0)

10+ Year Member



Thanks Guys - worked like a charm.

for what it is worth, I ended up with:

$url = $_SERVER['SERVER_NAME'];
$url = str_replace('www.', '', $url); /* removes the 'www.' */
$url = str_replace('.biz', '', $url); /* you'll get the rest */
$url = str_replace('-', ' ', $url);
echo $url;