[php] Word censor skripta

[php] Word censor skripta

offline
  • Pridružio: 21 Apr 2007
  • Poruke: 98

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/



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • PHP developer
  • Pridružio: 22 Mar 2006
  • Poruke: 3654
  • Gde živiš: 127.0.0.1

Isto to, samo malo drukcije Wink

function censor($text, $censored_words = "", $length = 2, $rep = "*") {       $words = explode(",",$censored_words);       $replace = array_map(function($word) { return substr($word,0,$length).str_repeat('*',strlen($word)-$length); },$words);       return str_ireplace($words,$replace,$text);    }

I rezultat:

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*.lipsum.com/



offline
  • Pridružio: 10 Avg 2006
  • Poruke: 1009
  • Gde živiš: Beograd

skretanje sa teme, al sam morao da prokomentarišem : ja sam skroz protiv cenzure svih vrsta, ali posebno ove. Konkretno za ovu: Menjanje recimo normalne reči u reč je***e SAMO skreće pažnju na tu reč. I dete od 5 godina će svahiti šta treba tu da stoji i tek će mu tad to biti zanimljivo. Time se samo gubi na čitljivosti sadržaja. Ako je zabranjen takozvani "vulgaran" sadržaj, treba potpuno blokirati sve tekstove koji uopšte sadrže te reči, a ne samo zameniti slova reči zvezdicama.

offline
  • Pridružio: 21 Apr 2007
  • Poruke: 98

Slažem se...donekle. Ovakve skripte mogu i cenzurisati spam poruke, neželjene linkove itd.

Bolja je varijanta da na primer ako postoji neka reč, koja je cenzurisana u tekstu, isti ne bude "publish" nego "under moderation". Ali to je već druga priča. Smile

Ili da se definiše zamena za svaku reč (search and replace metoda).

offline
  • Blood  Male
  • Ugledni građanin
  • Pridružio: 26 Jul 2003
  • Poruke: 384
  • Gde živiš: Beograd

^najbolje bi bilo ljude nauciti bonton-u, pa nam onda ovakve funkcije ne bi ni trebale ;-)

Ko je trenutno na forumu
 

Ukupno su 596 korisnika na forumu :: 33 registrovanih, 8 sakrivenih i 555 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3028 - dana 22 Nov 2019 07:47

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 8u47, A.R.Chafee.Jr., apostata, awathorn, Bane san, cvrle312, darkangel, Djokkinen, djordje92sm, dogodine, dragon986, Duško, Georgius, GUARIN, havoc995, ivica976, komkom, Markoni29, Mirage 2000N, nemkea71, nikolapetkovic, ofbeyond, operniki, Pohovani_00, Recce, StepskiVuk, Toni, uruk, VaRvArI 85, vathra, Viceroy, zile54, zillbg