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()
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';
}
精彩评论