Wäre dann das Script nicht sehr langsam ,wenn er alle 10.000 vergleichen müsste.
Teste es selber:
PHP
<?php
$time_start = microtime(true);
function match($badwords, $string)
{
$result = false;
foreach($badwords as $badword)
{
if (stripos($string, $badword) !== false)
$result = true;
}
return $result;
}
$badwords = array();
for ($i = 0; $i < 10000; $i++)
$badwords[] = "depp" . $i;
$s = "Manch einer ist ein Depp, oder Depp9999, oder was auch immer";
$result = match($badwords, $s);
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($result)
echo "Gefunden<br>";
else
echo "Nicht gefunden<br>";
echo "In $time Sekunden erledigt<br>\n";
?>
Alles anzeigen