Fellow php Programmers,
I have found many code samples (mentioned below) and adjusted according to my needs. Just one trouble. On each of the following ways I coded, how do I write code to echo the banned word who’s match has been found on the page ?
Notice the CAPITAL SENTENCE on all samples.
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//script 1: https://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array
//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.
$yourWord='evil';
$targets = array("evil", "devil");
if (in_array($yourWord, $targets)) {
echo "Sciptt 1 - Found Banned Word: $targets";
}
?>
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//script 2: https://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array
$keywords=array('one','two','three');
$targets=array('eleven','six','two');
foreach ( $targets as $string )
{
foreach ( $keywords as $keyword )
{
if ( strpos( $string, $keyword ) !== FALSE )
{ echo "Script 2 - Found Banned Word: $targets"; }
}
}
?>
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
<?php
//script 3: https://stackoverflow.com/questions/13795789/check-if-string-contains-word-in-array
$string = "There are evil devils all over the place!";
$banned_words = array('evil', 'devil');
foreach($banned_words as $band_word) {
$place = strpos($string, $band_word);
if (!empty($place)) {
echo "Script 3 - Found Banned Word: $band_word";
exit;
} else {
echo "No banned words found!";
}
}
?>
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//script 4 : https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string
foreach ($banned as $v) {
if (stripos($email,$v) > -1){
echo "Script 4 - Found Banned Word: $v";
}else{
echo 'Email signed up!';
}
}
?>
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//script 5: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string
$banned = array("evil", "devil", "blah", "*", "#", "$", "%");
//$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]";
?>
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//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 THE SEE SNIPPET EXAMPLE";
}
?>
<?php
/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
//script 7: https://stackoverflow.com/questions/32522192/check-if-an-array-element-is-in-a-string
$banned = array("evil", "devil", "blah", "*", "#", "$", "%");
//$email = $_POST['email'];
$email = "evil@devil.com";
foreach ($banned as $ban) {
if (stripos($email, $ban) !== FALSE) {
echo "Script 7 - Found Banned Word: $ban";
return true;
}
}
echo "No banned words found.";
return false;
?>
I’d appreciate it, if you guys add the missing code to display the matched banned word found on the webpage and paste the code so we newbies flooding this way can see the missing puzzle peaces and learn from them! I need help on SCRIPT 6. 
Would appreciate it if you can check the other 5 scripts out. Especially check SCRIPT 5 as I am not sure if I done it correct.
Also, on SCRIPT 1, I get this echo:
Script 1 - Found Banned Word: Array
Thanks!