If you are wanting to know which keyword(s) is/are found, there is one flaw in your logic - it exits the function on the first keyword found. What if there are two or more keywords that are found? Instead of returning true on the first keyword found, I'd suggest adding the found keywords to an array. Then return the array. Also, I would assume you would want to do a case insensitive search. E.g. if you have "spamword1", you would want a match on something like "SpAmWoRd1". If so, you would want to use stripos()
Give a look at this:
$uri = $_SERVER['REQUEST_URI'];
$spam_keywords = [
'spamword1',
'spamword2',
'spamword3'
// WILL BE A LOT MORE HERE
];
function checkKeywords($uri, $keywords) {
$foundKeywords = array(); //Create array to hold found keywords
foreach ($keywords as $keyword) { //Iterate over list of keywords
if (stripos($uri, $keyword) !== false) { //Check if keyword is in $uri
$foundKeywords[] = $keyword; //Add found keyword to array
}
}
//Return found keywords
return $foundKeywords;
}
//Check for keywords
$foundKeywords = checkKeywords($uri, $spam_keywords);
//Check if results are not empty
if (!empty($foundKeywords)) {
//Keywords were found - display them
echo "<p>The following Keywords were found:" . implode(', ', $foundKeywords) . "</p>";
} else {
//No keywords found
echo "keywords not found";
}