php - Replace simple quote and double quote -
i have variable in mysql database. want variable handle both simple , double quotes.
for example:
$variable = "i'm happy" or $variable = i'm happy or $variable = "i happy"
in db, first example this: "i'm happy"
, works me. problem on js function because want call data:
namefolder = "<?php echo $variable ; ?>"
but, if $variable = "i'm happy"
, i've got double ""
js error. , if put single quote, problem same case.
any ideas?
the best way echo data javascript use json_encode
:
var namefolder = <?php echo json_encode($variable); ?>;
n.b.: there shouldn't surrounding quotes, function handle you.