tags:

views:

61

answers:

2

Hello all..

i'm wondering how to check if a string like : http://www.reddit.com/xxx/x/xxx contains the word : reddit.com

that string could contains or not contains reddit.com

and if it contains , it execute my function : itsReddit()

maybe with preg match? or something like this?

Please i don't want a link for tutorial, i only need a php code for this, & THANKS soo much!

+2  A: 
  if(strpos($your_link, 'reddit.com') !== FALSE) itsReddit();
antpaw
Thanks man, you saved me!
David
I don't know what the purpose of this is for, but wouldn't this make it easy to just fudge a link (like `http://somemaliciouslink.com/?reddit.com`)?
Carson Myers
+2  A: 
$input = 'http://www.reddit.com/xxx/x/xxx';
if ( false!==stripos($input, 'reddit.com') ) {
  //itsReddit();
  echo 'reddit';
}

Or if you want to test if the host is reddit.com

$input = 'http://www.reddit.com/xxx/x/xxx';
$host = parse_url($input, PHP_URL_HOST);

if ( false!==stripos($host, 'reddit.com') ) {
  //itsReddit();
  echo 'reddit';
}
VolkerK
Thanks too, both works for me also.
David