Im trying to do a bad words filter with the following function:
function sacarmalaspalabras($texto) {
$palabras = Array(" sexo "," concha ", " pete "," vagina ", " culo ", " anal ", " puta ", " puto ", " putas ", " putos ", " preservativo ", " preservativos ", " orgasmo ", " porno ", " pija ", " teta " , " tetas ", " condon ", " masturbar ", " masturbaba ", " poronga ", " concha ", " hentai ", " gay ", " lesbiana ", " orto ", " choto ", " chota ", " marica " ," maricon ", " semen ", " garchar ", "hentai","porn"," porn " );
$palabrasnew = Array(" s*xo "," c*ncha ", " p*te ", " v*gina ", " cul* ", "an*l ", " p*ta ", " p*to ", " p*tas ", " p*tos ", " preservativ* ", " preservativ*s ", " or**smo ", " p*rno ", " pij* ", " tet* ", " tet*s ", " cond*n ", " mastur*** ", " mast**baba ", " poron** ", " conch* " , " h**tai ", " g*y ", " lesb**na ", " ort* ", " chot* ", " chot* ", " maric* ", " maric*n ", " sem*n ", " garch** ", "h**tai", "p*rn", " p*rn " );
$texto = str_replace($palabras,$palabrasnew,$texto);
return $texto;
}
the problem is that its replacing the word only if its between white spaces lets say i want to filter the word "ass" , if someone says: "that ass, another thing" it will not replace it due to the comma. But also i want to prevent the replacement of words inside other words, lets say im trying to filter the word "sex" but i dont want to filter "sexuality".
how can i use a wildcard on str_replace? so its something like %ass% there might be some words that will fall in the filter, but it will be the minority.