If you replace
$queryJoin = $serverUrl . $getContents;
with
$queryJoin = strtolower(urldecode($serverUrl . $getContents));
You can change
if (strpos(strtolower(urldecode($queryJoin)), strtolower($search)) !== false) {
to
if (strpos($queryJoin, strtolower($search)) !== false) {
and save a strtolower call and urldecode call for every iteration.
For that matter, if the keys are constants, as they are here, you could simply drop the strtolower on $searches as well. Just make sure that the values are lower case.
Alternatively, consider making a check class.
class URL_Checker {
protected $searches;
public function __construct($searches) {
$this->searches = array_map('strtolower', $searches);
}
public function check($string) {
$haystack = strtolower(urldecode($string));
foreach ($this->searches as $search) {
if (false !== strpos($haystack, $search)) {
return true;
}
}
return false;
}
}
That would work better if you are calling the function multiple times for the same search keys.
Just as a matter of good style, it would be better to separate loading the data from checking it. This class would be reusable for any data string. Or you could load the body of the request once and reuse it multiple times. Your original form would allow neither input nor processing reuse.
It's possible that replacing the foreach with an array_reduce might be more efficient on average. You'd have to run metrics. It would tend to improve the worst case at the cost of the best case; that might be a useful tradeoff regardless. The worst case being when the search keys do not appear so you have to check all of them.
$getContents = file_get_contents('php://input');is only aiming to get query string variables, right? or is it intended to include POST data also? \$\endgroup\$