jasonc Posted March 20, 2009 Share Posted March 20, 2009 i have tried to use the strstr() but this only returns the string after the phrase i am looking for. i dont need to know where it is just if the string has the phrase in it or not. how is this done? Link to comment https://forums.phpfreaks.com/topic/150347-find-out-if-string-contains-xyz/ Share on other sites More sharing options...
php.ajax.coder Posted March 20, 2009 Share Posted March 20, 2009 i think you can use if(ereg("xyz", $string){ } Link to comment https://forums.phpfreaks.com/topic/150347-find-out-if-string-contains-xyz/#findComment-789588 Share on other sites More sharing options...
jackpf Posted March 20, 2009 Share Posted March 20, 2009 Ereg is deprecated. I think this is preferred... if(preg_match('/xyz/', $str)) { echo 'Match!'; } Link to comment https://forums.phpfreaks.com/topic/150347-find-out-if-string-contains-xyz/#findComment-789591 Share on other sites More sharing options...
thebadbad Posted March 20, 2009 Share Posted March 20, 2009 If it's just a simple string like xyz, strpos() is fastest: <?php if (strpos($str, 'xyz') !== false) { //found } ?> Link to comment https://forums.phpfreaks.com/topic/150347-find-out-if-string-contains-xyz/#findComment-789600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.