ho un database con due campi (testo pre) che usano codici tipo [ b ] e dovrei cambiare tutto in html semplice
come posso fare? lo script sotto mi fallisce nei testi contenenti ', quale era la funzione per fare l'escape?
oppure c'è un metodo migliore?
Codice PHP:
$news = mysql_query("SELECT id, pre, testo FROM news");
$s1 = "[b]";
$s2 = "[/b]";
$t1 = "[ b ]";
$t2 = "[ /b ]";
while ($x = mysql_fetch_array($news)) {
$testo = str_replace($t1, $s1, $x["testo"]);
$testo = str_replace($t2, $s2, $x["testo"]);
$pre = str_replace($t1, $s1, $x["pre"]);
$pre = str_replace($t2, $s2, $x["pre"]);
qry("UPDATE `news` SET `testo` = '$testo', `pre` = '$pre' WHERE id='$x[id]'");
}