Php Kelime Filtresi
-
selam hacılar php ile kelime filtresi yapmaya calısıyorum ancak dizinin içindeki bütün kelimeleri sorgulamıyor nasıl yapabilirim bu işi
<?php function keyword_filter($string) { $keywords = array('fuck','suck','motherfucker'); $count = count($keywords); for ($ix=0;$ix<=$count-1;$ix++) { $check = preg_match("/$keywords[$ix]/i", $string); if($check==true) { return false; } else { return true; } } } $s = 'suck man yo yo'; if(keyword_filter($s)==true) { print 'yok';} else {print 'var';} ?> -
explode ile kelimeleri ayırırsın sonra in_array ile kontrol edersin for içinde, regex'e gerek yok.
-
str_replace ye array sokunca hepsini tarıyor. '' ile değiştirirsin kelimeyi sonra bi ifle değişim olup olmadığını kontrol edersin. forla falan tek tek tüm kelimeleri taratma yükü olmaz hem
-
str_replace'in true yada false değeri döndürdüğünü nasıl bulcam
değişkene atayıp
true mu diye baktığımda olmuyor
edit tamadir btane daha arguman alıyomus oda değiştirilen kelimeleri sayıyormuş
Realist tarafından 06/Kas/13 19:17 tarihinde düzenlenmiştir -
ana metin ile değişen metin eşitmi diye bakıcaksın zaten
-
strposda kullanabilirsin
http://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos burdada örneği mevcut
function strposa($haystack, $needles=array(), $offset=0) { $chr = array(); foreach($needles as $needle) { $res = strpos($haystack, $needle, $offset); if ($res !== false) $chr[$needle] = $res; } if(empty($chr)) return false; return min($chr); }
//kullanım$string = 'Whis string contains word "cheese" and "tea".'; $array = array('burger', 'melon', 'cheese', 'milk'); if (strposa($string, $array, 1)) { echo 'true'; } else { echo 'false'; } -
işine yarayan kullanır belki alın hacılar
<?php function keyword_filter($string) { $keywords = array('gay','suck','motherfuck'); $check = str_replace($keywords,'',$string,$count); if($count>0) {return true;} else {return false;} } ?> -
Benim kullandığım fonksiyon
kufur.php<?php /* bosluk == separator */ $kotu=array(); $kotu[]='union'; $kotu[]='select'; $kotu[]='refresh'; $kotu[]='kasar'; $kotu[]='maldini'; ?>
fonksiyomuzfunction yasak($t){; include 'kufur.php'; $kelime=$kotu; for($i=0;$i<count($kotu);$i++){ $row=explode(' ',$kotu[$i]); $t=str_ireplace($row[0],"***",$t);} return $t;}Kullanımı
<?php yasak($degisken); ?>
