Forum Moderators: coopster

Message Too Old, No Replies

what is wrong with my reg ex

preg_replace dose not do the trick for me.

         

sweethilit

4:30 pm on Apr 25, 2006 (gmt 0)

10+ Year Member



Hi every one,
I have been trying to perform rather simple perg_replace with no success, so maybe it is not as simple as I think or I am not smart as I believe :-)
the regex:
$regex = "/((http:\/\/¦www\.¦http:\/\/www\.)(?!mysite)[-&,%~;=.\/\d\w\?]+)/i";
it is intended to match any link that is NOT my site but with no success.
so doesn't this regex:
$regex = "/((http:\/\/¦www\.¦http:\/\/www\.)[^m][^y][^s][^i][^t][^e][-&,%~;=.\/\d\w\?]+)/i";

help will be appreciated!

coopster

10:34 pm on Apr 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, sweethilit.
$mysite = 'example.com'; 
$pattern = "/(http:\/\/)?(www\.)?$mysite/i";
if (!preg_match($pattern, $site)) {
// bad site
}

This finds a site within a link that starts with an optional http:// followed by an optional 'www.'. If it doesn't match our site, we reject it.