censor a word registered in a database

1

Is there a way to censor and replace a MySQL registered word with a procedure or trigger for example? The word in the case would be Flash House and need to be replaced by Old School .

    
asked by anonymous 05.09.2017 / 03:52

2 answers

2

Idea:

Catch the words that will be censored from the database, and pass these to an Array. With the generated arrays, use replace to replace.

How would we do:

Imagine that we have the following table named Censura :

(Palavra_Censurada, Palavra_Substita)
('Flan House', 'Old Schol')
('Palavra3', 'Palavra4')

In PHP we would pass the values of this table to an array as in the example

<?php
$consulta = mysqli_query($conexao, "select Palavra_Censurada, Palavra_Substituta from censura");
$ind = 0;
while($dados = mysqli_fetch_array($consulta)) {
$censura[$ind][palavra] = $dados['Palavra_Censurada'];//Passa Valores da Tabela para o Array
$censura[$ind][substituto] = $dados['Palavra_Substita'];
$ind++;
}
$texto = "Seu texto que será censurado"; // Seu Texto Aqui
$ind = 0;
while($ind < count($censura)) { //Conta Número de Arrays
str_replace($censura[$ind][palavra], $censura[$ind][substituto], $texto);// Substring
$ind++;
}
?>
    
06.09.2017 / 02:48
1

Depending on your application, it is best to do this on the client side with JS , or server , because the server will be very complex and use a lot of resources on your machine because this thread will have to be running \ listening when you find that word that is already persisted, make a update , not to mention the security issue, because how will you guarantee rollback ?

    
05.09.2017 / 04:31