2
I’m going through a database of a friend who had some data entered wrong or a little confused or I’m the one who’s making it difficult.
Ex: Mariana "Gurizinha’s"
This example was saved in the bank as follows: \'Gurizinha\'s\'
To display on his website I tried to create a function which replaces the initial character with a " and the ending also with ".
Right would be to pick up a text that was saved that way and that has 100 words or more and correct displaying: "Gurizinha's"
instead of \'Gurizinha\'s\'
.
Then my head tied a knot str_replace
it will take all the text and whatever has ' will change to " so if it is words that need Are’s it will replace by ".
function rt_especial($valor) {
$i = 0;
$palavras = explode(' ', $valor);
foreach($palavras as $Arr) {
$i++;
$novotexto = stripcslashes($Arr);
$i2 = 0;
$palavras2 = explode("'", $novotexto);
foreach($palavras2 as $Arr2) {
$i2++;
}
for($i3 = 0; $i3 <= $i2; $i3++) {
$str = '"';
$str .= $palavras2[$i3];
}
}
echo substr($string, -1);
$novotexto = join(' ', $novotexto);
return $novotexto;
}
Code entering data into Mysql database:
function db_executa($tabela, $dados, $acao = 'insert', $parametros = '') {
reset($dados);
if (strtolower($acao) == 'insert') {
$consulta = 'insert into ' . $tabela . ' (';
while (list($coluna, ) = each($dados)) $consulta .= $coluna . ', ';
$consulta = substr($consulta, 0, -2) . ') values (';
reset($dados);
while (list(, $valor) = each($dados)) {
switch ((string)$valor) {
case 'now()':
$consulta .= 'now(), ';
break;
case 'null':
$consulta .= 'null, ';
break;
default:
$consulta .= '\'' . db_entrada($valor) . '\', ';
break;
}
}
$consulta = substr($consulta, 0, -2) . ')';
} elseif (strtolower($acao) == 'update') {
$consulta = 'update ' . $tabela . ' set ';
reset($dados);
while (list($coluna, $valor) = each($dados)) {
switch ((string)$valor) {
case 'now()':
$consulta .= $coluna . ' = now(), ';
break;
case 'null':
$consulta .= $coluna .= ' = null, ';
break;
default:
$consulta .= $coluna . ' = \'' . db_entrada($valor) . '\', ';
break;
}
}
$consulta = substr($consulta, 0, -2) . ' where ' . $parametros;
}
return db_consulta($consulta);
}
Solving part of the problem: It’s not a pretty way and much less certain, but it’s the one I got to solve.
function rt_especial($valor){
$string = $valor;
$separa = explode(" ", $string); // quebra a string nos espaços
$count = count($separa); // quantidade de separações
$arrayok = array();
for($i=0; $i<= $count; $i++)
{
// Pego toda palavra que começa com \' e substituo por "
$string2 = ereg_replace("^([/\'])", '"',$separa[$i]);
$string3 = str_replace("\',", '",', $string2);
$string4 = str_replace("\',", '",', $string3);
$string5 = ereg_replace('^([/""])', '"',$string4);
$string6 = ereg_replace('([/""])$', '"',$string5);
//Pego toda palavra que termina com \' e substituo por "
$string = ereg_replace("([/\'])$", '"',$string6);
$string7 = str_replace('"\'', '"', $string);
$string8 = str_replace("\'\"", '"', $string7);
$string9 = str_replace('\"', '"', $string8);
$arrayok[$i] = $string9;
}
$ccp = implode(' ', $arrayok);
return $ccp;
}
Because he was saved in the bank this way
\'Gurizinha\'s\'
? What was the problem with the bank? extremely do not recommend to make a Gambi these but if necessary we can help... but surely it would be better to fix the problem of the bank instead of creating a function of these.– Paulo Roberto Rosa
He used an incorrectly configured javascript text editor (Javascript Swing) and he is doing so with all the inserted text. Since he already has over 1200 ID’s in the bank.
– joao_coelho
Check the Javascript Swing configuration, and let us know, because depending, a simple text editor can reverse this.
– Paulo Roberto Rosa
I will post an answer containing the code responsible for saving to the bank. The error should be in it and not in the editor. Sorry.
– joao_coelho
Is recorded data javascript code? Can you post more examples? Text always starts and ends with quotation marks? Because the first quotation marks are necessary and the others not? We need a deterministic means to know which quotes are "necessary" and which ones are not.
– utluiz
Really, it should be in itself :) I found it strange a text editor to do this...
– Paulo Roberto Rosa
@user Do not include an answer, edit the question.
– utluiz
this is the code the data goes through when clicking save. it saves a text like a blog that may or may not contain HTML.
default:
 $consulta .= '\'' . db_entrada($valor) . '\', ';
 break;
– joao_coelho
I believe the right thing would be:
default: $consulta .= "'".db_entrada($valor)."'",'; break;
– Paulo Roberto Rosa
Could post the full code to record?
– Paulo Roberto Rosa
As a newbie, stackoverflow is not allowing me to post the entire code or create a new answer.
– joao_coelho
I edited the question and entered the code you enter in the bank.
– joao_coelho
This looks like the kind of problems that Magic Quotes cause.
– luiscubal
Edited question.
– joao_coelho