I have a function, function is that.
<?php
function sanitize_core($text)
{
global $bannedWords;
$text = htmlspecialchars($text, ENT_NOQUOTES);
$text = str_replace("\n\r","\n",$text);
$text = str_replace("\r\n","\n",$text);
$text = str_replace("\n"," <br> ",$text);
$number_word = explode(" ",$text);
for($x=0;$x<count($number_word);$x++)
{
for ($i=0;$i < count($bannedWords);$i++)
{
if (stripos($text, $bannedWords[$i]) !== false)
{
/*$pos = stripos($text, $bannedWords[$i]);
$word = substr($text,$pos,strlen($bannedWords[$i]));
$first = substr($text,0,$pos);
$final = substr($text,$pos+strlen($bannedWords[$i]),strlen($text)-($pos+$bannedWords[$i]));
$text = $first.str_repeat("*",strlen($bannedWords[$i])).$final;*/
$text = str_ireplace($bannedWords[$i], str_repeat("*",strlen($bannedWords[$i])), $text);
}
//$text = str_ireplace(' '.$bannedWords[$i].' ',' '.str_repeat("*",strlen($bannedWords[$i])).' ',' '.$text.' ');
}
}
$search = array('Ç','ç','Ğ','ğ','ı','İ','Ö','ö','Ş','ş','Ü','ü');
$replace = array('c','c','g','g','i','i','o','o','s','s','u','u');
$text = str_replace($search,$replace,$text);
$text = trim($text);
return $text;
}
$bannedWords = array( 'fuck','0','sakaci' );
$test_word = "a 1 2 5 s p o c X";
echo sanitize_core($test_word);
?>
The functions is works perfect, so dont remove anything, ı wanna only add something.
if I write only one letter, it should replace with * so you need to add minumum strlen.
Examples,
if I echo
H e l l o
or
H
all will * because if one letter after space , it will * (because minumum word should 2 )
if I echo only "H" it will also *
So edit this function and send me.