Napisao sam jednu skriptu koja cenzuriše zadate reči. Interesuju me neke vaše ideje kako bi poboljšao skriptu.
Meni se ne sviđa to što koristim petlju u petlji (2 loop-a). Drugu petlju koristim da dobijem broj znakova za cenzurisanu reč i da je toliko puta zamenim sa npr "*".
Skripta:
<?PHP
function censor($text, $censored_words = "", $length = 2, $rep = "*") {
$words = explode(",",$censored_words);
$temp_text = $text;
for($i=0; $i < count($words); $i++){
$fletter = substr($words[$i],0,$length);
$let = "";
for($ii=0; $ii < strlen($words[$i])-$length; $ii++){
$let.=$rep;
}
$return = str_ireplace($words[$i] , $fletter.$let , $temp_text);
$temp_text = $return;
}
return $return;
}
?>
Korišćenje:
Citat:censor(ARG1, ARG2, ARG3,ARG4);
ARG1 - tekst koji treba da se filtrira
ARG2 - Cenzurisane reči odvojene zarezom
ARG3 - Koliko prvih znakova prikazati (npr. ako su 2 dobijamo sh**)
ARG4 - Znak koji menja slovo u cenzurisanoj reči
Citat:censor("tekst", CENZURISANE_RECI, 2, "*");
Primer:
$cenzura= "Lorem,Ipsum,www,1960,http,version,content,popular";
echo censor("<br />Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. <br />http://www.lipsum.com/ <br /> <br />",$cenzura,2,"*");
Dobijamo ovo:
Citat:Lo*** Ip*** is simply dummy text of the printing and typesetting industry. Lo*** Ip*** has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was po*****ised in the 19**s with the release of Letraset sheets containing Lo*** Ip*** passages, and more recently with desktop publishing software like Aldus PageMaker including ve*****s of Lo*** Ip***.
ht**://ww*.lIp***.com/
|