php slashes expression
I have a html like this
<div><font color="green">ABC</font>A'ssd"开发者_如何学Gofsdf</div>
i need to change the above as
<div><font color=\"green\">ABC</font>A'ssd"fsdf</div>
that is \" appears only in html component , not in text data.
in php how?
i want to do the above thing as follows
var a = "<div><font color=\"green\">ABC</font>A'ssd"fsdf</div>";
in Javascript.
If you want to do this, you also want to escape the "
in the text, or it will break your Javascript syntax just the same. The answer is to encode it in the JSON format:
<?php
$html = <<<HTML
<div><font color="green">ABC</font>A'ssd"fsdf</div>
HTML;
?>
<script type="text/javascript">
var a = <?php echo json_encode($html); ?>;
</script>
And seriously, don't use <font>
. Learn CSS. :)
精彩评论