graham23s Posted June 22, 2010 Share Posted June 22, 2010 Hi Guys, I'm trying to write a descripton, if the description contains [any of these words] ignore: <?php $ignoreWords = array( "Commission", "commission", "affiliate", "Affiliate", "affiliates", "Affiliates", "Conversion", "conversion", "conversions", "Conversions", "Earn", "earn" ); if (in_array($pdcD, $ignoreWords)) { $newDescription = "For further information please click <b><a href=\"$url\" target=\"_blank\">here</a></b>."; } else { $newDescription = $pdcD; } ?> If tghe description contains any of those words do the first option else do the second but when testing it doesn't work it executes the second option. any help would be appreciated thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/205589-ignoring-keywords/ Share on other sites More sharing options...
Alex Posted June 22, 2010 Share Posted June 22, 2010 You can create a custom function to do this, something like this: function strpos_many($haystack, $needle) { foreach($needle as $val) { if(strpos($haystack, $val) !== false) { return true; } } return false; } What this does is check to see if any of the words in the array are found in the string. If one is, it returns true. If none are, it returns false. strpos Then use it like this: if(strpos_many($pdcD, $ignoreWords)) { $newDescription = "For further information please click <b><a href=\"$url\" target=\"_blank\">here</a></b>."; } else { $newDescription = $pdcD; } Quote Link to comment https://forums.phpfreaks.com/topic/205589-ignoring-keywords/#findComment-1075819 Share on other sites More sharing options...
graham23s Posted June 22, 2010 Author Share Posted June 22, 2010 Ah thank you Alex that worked perfectly Graham Quote Link to comment https://forums.phpfreaks.com/topic/205589-ignoring-keywords/#findComment-1075828 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.