How to work with arrays in PHP or a word filter

We need to make a request filter, there is a variable $requestthat contains a request from a visitor, there is a second variable $bad_wordthat stores a list of forbidden words in a file in format bad_word' => ", , "uses a comma and a space to separate words.
It is necessary to make it so that if any word from the $bad_wordvariable matches, the $requestvariable takes an empty value.
It is desirable that the words from bad_wordcould be used case-insensitive.
I myself have little knowledge of PHP, you can say a beginner, but you need to do it now.
Thank you, I will be grateful for any hints.

Answer 1, authority 100%

In order to get an array of words from the string $bad_word, use the function explode(), foreachloop is suitable for iterating and checking all array elements , you can use stripos().

to search for words in a sentence.

Answer 2

You just need to find the occurrence of a substring in a string. Use mb_stripos()which, unlike stripos()works with UTF-8 characters.

$needle = trim($request);
if(mb_stripos($bad_word, $needle) !== false){
    $request = null;