How To Count Banned Words On Page?

I just added that line as you suggested but my script is not executing all the lines.
Why is that ?
There are 8 snippets but only 2 are getting executed! Strange!
Ok, it does not matter whether all the 8 are perfect or not. It should either show all their results or errors if any snippet is out of touch. Right ?

<?php

/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

/*
Formula:
returns true if $needle is a substring of $haystack
function contains($needle, $haystack)
{
    return strpos($haystack, $needle) !== false;
}
*/

//script 1: https://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array
//http://php.net/manual/en/function.in-array.php
//Simplest check.

$content = 'evil';
$targets = array("evil", "devil");

if (in_array($content, $targets)) {
    echo "Script 1 - Found Banned Word: HOW TO DISPLAY MATCHING WORD HERE ?";
}
?>
<br>


<?php
//script 2: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string

$banned = array("evil", "devil");
//$email = $_POST['email'];
$email = "evil@devil.com";

    foreach ($banned as $ban) {
        if (stripos($email, $ban) !== FALSE) {
            echo "Script 2 - Found Banned Word: $ban";
            return true;
        }
    }
    echo "No banned words found.";
    return false;
?>
<br>


<?php
//script 3: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string

$banned = array("evil", "devil");
//$email = $_POST['email'];
$email = "evil@devil.com";

foreach ($banned as $ban) {
    if (stripos($email,$ban) > -1){
        echo "Script 3 - Found Banned Word: $ban";
    }else{
        echo 'Email signed up!';
    }
}

?>
<br>


<?php
//script 4: https://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array

$content = "There are evil devils all over the place!";
$banned_words = array('evil', 'devil');

foreach($banned_words as $band_word) {
    $place = strpos($content, $band_word);
    if (!empty($place)) {
        echo "Script 4 - Found Banned Word: $band_word";
        exit;
    } else {
        echo "No banned words found!";
    }
}
?>


<?php
//script 5: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string

$banned = array("evil", "devil");
//$email = $_POST['email'];
$email = "evil@devil.com";
$banned = false;

for($i=0; $i < count($banned); $i++) {
    if(strrpos($email, $banned[$i]) != FALSE ) {
       $banned = true;
       break;
    }
}
echo "Script 5 - Found Banned Word: $banned[$i]";

?>
<br>


<?php
//script 6: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string

//$email = $_POST['email'];
$email = "evil@devil.com";

if(preg_match("/\b(evil|devil)\b/", $email)){
    echo "Script 6 - Found Banned Word: HOW DO I DISPLAY THE FOUND BANNED WORD HERE ? WOULD LIKE TO SEE SNIPPET EXAMPLE";
}

?>


<?php
//script 7: https://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array

//Checking arrays against other arrays
$keywords = array('evil','devil','satan');
$targets = array('monster','satan','devil');
foreach ( $targets as $string ) 
{
  foreach ( $keywords as $keyword ) 
  {
    if ( strpos( $string, $keyword ) !== FALSE )
     { echo "Script 7 - Found Banned Word: $string"; }
  }
}
?>
<br>


<?php

/*
Formula:
returns true if $needle is a substring of $haystack
function contains($needle, $haystack)
{
    return strpos($haystack, $needle) !== false;
}
*/
$banned_words_count = 0;
$article = "TEST ARTICLE
This is an article to see if our php script can spot any banned words in it or not.
These are the banned words: Evil, Devil.
Since this article contains these 2 banned words then our php script should be able to spot them and count them to 2.
End of article.";
$banned_words_1 = 'Evil';
$banned_words_2 = 'Devil';
if (strpos($article, "banned_words_1") == true) {
    echo 'Banned word found: "$banned_words_1"';
}
if (strpos($article, "banned_words_2") == true) {
    echo 'Banned word found: "$banned_words_2"';
}
if (preg_match("/banned_words_1/",$article))
    echo 'Banned word found: "$banned_words_1"';
if (preg_match("/banned_words_2/",$article))
    echo 'Banned word found: "$banned_words_2"';

echo '<br>line: ' .__line__;
    
?>

Notice your LINE at the final line, John_Betong! :wink:
Let us see if we can spot why the other snippets are not executing without the var_dump. :wink:
This is what I see:

Script 1 - Found Banned Word: HOW TO DISPLAY MATCHING WORD HERE ?
Script 2 - Found Banned Word: evil