Creo dinamicamente un array in javascritp con i valori che ho sul database. Quest'operazione di inserimento elementi avviene tramite il php. Il problema è che quando inserisco una stringa con apostrofi, ad es. A_accentatA' genera l'errore:
Unterminated string literal
Ho provato a fare l'escape tramite l'istruzione addslashes del linguaggio php, ma non funziona.... come si risolve?????
Thx!!
var arItems = new Array()
arItems = [
['1','1','azienda 1 categ A'],['1','26','A_accentatA'']
]
<script>
var arItems = new Array()
arItems = [
<?
$cmd = "SELECT * FROM $table_aziende";
$rs = mysql_query($cmd);
$tot=mysql_num_rows($rs);
$cont=1;
if (ini_get('magic_quotes_gpc') == 0)
$slash="y";
while($aItems = mysql_fetch_array($rs)){
$label=$aItems['label'];
if ($slash == "y")
$label=addslashes($label);
if ($cont==$tot){
echo "['".$aItems['id_categoria']."','" .$aItems['id']."','".$label."']";
}else{
echo "['".$aItems['id_categoria']."','" .$aItems['id']."','".$label."'],";
}
$cont++;
}
?>
]
</script>