开发者

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. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜