Jump to content

Ignoring keywords


graham23s

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/205589-ignoring-keywords/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/205589-ignoring-keywords/#findComment-1075819
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.