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 .
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 .
Catch the words that will be censored from the database, and pass these to an Array. With the generated arrays, use replace
to replace.
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++;
}
?>
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
?