CodeOverload
CodeOverload

Reputation: 48485

How to Check if a link string contains a word? (PHP)

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!

Upvotes: 0

Views: 1678

Answers (2)

VolkerK
VolkerK

Reputation: 96159

$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';
}

Upvotes: 2

antpaw
antpaw

Reputation: 15985

  if(strpos($your_link, 'reddit.com') !== FALSE) itsReddit();

Upvotes: 2

Related Questions