开发者

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

开发者 https://www.devze.com 2022-12-15 11:33 出处:网络
i\'m wondering how to check if a string like : http://www.reddit.com/xxx/x/xxx contains the word : reddit.com

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()

mayb开发者_如何学Goe 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!


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


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

精彩评论

暂无评论...
验证码 换一张
取 消