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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.