censor a registered word in a database

Asked

Viewed 62 times

1

Is there a way to censor and replace a word registered in Mysql through a precedent or Trigger for example? The word in the case would be Flash House and I need it replaced by Old School.

  • 3

    Take care of the case of clbuttic.

  • And if you use replace?

  • @Victorstafusa but it’s quite different in my case. I understand the concern. the need is to replace a term "brasileirado" by the correct and worldwide known.

  • 1

    @Renatosilva replace would be before doing INSERT?

  • @Fláviokowalske yes, this would be perhaps the most efficient way, already put the code here with the explanation

  • @Fláviokowalske you are using php?

Show 1 more comment

2 answers

2


Idea:

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

As we would do:

Imagine we have the following table called 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++;
}
?>

1

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

  • I imagine something like this: when a record is recorded from the base something happens and makes the conference and replace it if necessary. it will be in only one table.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.