如果json_encode一个字符串包含(&)在phtml中,浏览器将改变它的构造,如何防止它?

php:5.3.3

jquery:1.7.2

here is the way we use to send the value from php to jquery.

  1. get the escaped string.

$a = '"xxxxx'; $b = json_encode($a);

  1. and now, $b is '"xxxxx';

  2. put $a in phtml.

    php: $this->view->b = $b;

    phtml: <div id='my_data' style='display:none;'><?php echo $this->b;?></div>

so in the phtml, the string is

<div id='my_data' style='display:none'>"&quot;xxxxx"</div>

but, when the the string show in browser, it will become ""xxxxx"。And when we use $.parseJSON($("#my_data").text());. JQuery will throw an exception, because ""xxxxx" is not a JSON string.

so, how to resole this ?

or any other ways to send an escaped string from php to JQuery.

thank u all.