Alex Alex - 1 month ago 4x
MySQL Question

Php code to match string if any word is in array

I have been trying to match post query sting if it contain any word in array.
I try to execute sql query using the command to update or select but i don't want to drop or delete row and table.

Please bellow code is not matching the sting in array well


$RequestQuey = htmlspecialchars($_POST['QueryCode']);
$sqlchecker = strtolower($RequestQuey);
$bads_arrays = array(

foreach ($bads_arrays as $strings){
if (strpos($sqlchecker , $strings) !== false) {
echo "Match found";
return false;
echo "Not found!";
return true;


You are doing a strtolower() on the examined string but you have uppercase words in the array. So either replace strpos with stripos or change the words in the array to be lowercase or convert the examined string ($sqlchecker) to uppercase.

$anyMatched = false;
foreach ($bads_arrays as $strings){
    if (stripos($sqlchecker , $strings) !== false) {
        $anyMatched = true;

echo ($anyMatched ? 'Match found' : 'Not Found');
return $anyMatched;