views:

251

answers:

2

I need to get "yomomedia.com" if the HTTP_HOST is [ANY].yomomedia.com except in the cases where it is "dev.yomomedia.com" else it should return dev.yomomedia.com

echo preg_replace("/^([EVERYTHING-OTHER-THAN-DEV])\./Ui","",$_SERVER['SERVER_NAME'])

Just tried the following with no success:

echo preg_replace("/^(?!dev)\./Ui",'','www.yomomedia.com'); // returns www.yomomedia.com
echo preg_replace("/^(?!dev)\./Ui",'','dev.yomomedia.com'); // returns dev.yomomedia.com
+2  A: 

A negative passive group (lookahead) should do:

/^(?!dev).*\./Ui
Ignas R
Now it should really work. There should have been .* after the lookahead. I've added it now
Ignas R
thanks, Ignas, I am yet to get into the realm of lookahead and lookbehind when it comes to regex
farinspace
+1  A: 

Look-arounds do not “consume” any characters. So your expression means the same as the first three characters are not dev (^(?!dev)) AND the first character is a full stop (^\.).

So try either this:

/^(?!dev\.)[^.]+\./Ui

Or:

/^[^.]+\.(?<!^dev\.)/Ui
Gumbo