If your html code is not broken on inside of php variable, then it
won't break anything inside json_encode;
[code]
<?php
$html = '
<div id="someId">this is correct html
<span id=\'singleQuote\'>
You have to escape single Quotes
FOR PHP SAKE ONLY.
If you get the HTML from file, or from
database, then NO ESCAPING is needed.
You need to escape quotes only for PHP
parser, just as in any string.
</span>
</div>';
$json = json_encode($html);
echo $json;
?>
[/code]
//produces:
"\n <div id=\"someId\">this is correct html\n <span
id='singleQuote'>\n You have to escape single Quotes \n
FOR PHP SAKE ONLY. \n If you get the HTML from
file, or from \n database, then NO ESCAPING is needed. \n
You need to escape quotes only for PHP \n
parser, just as in any string.\n <\/span>\n <\/div>"
Json_encode() function does EVERYTHING that is needed to escape the
javascript strings, you do not need to have any kind of add_slashes().
In fact, add_slashes will break things, as the slashes will be escaped
by json_encode() funciton, and they will be visible in html.
Take a look if you have not over-escaped the html. You might have
magic-quotes enabled which automagicly adds slashes for you. This is
evil option, as you have little control over what is happening.
Hope this helps
> On Jun 4, 5:24 pm, "Alex McAuley" <webmas...@thecarmarketplace.com>
> wrote:
>> You need to do it a bit differently with php json_encode/decode ... i had
>> this problem when i first started using it....
>>
>> where you send post data (JSON) as p
>>
>> $post=str_replace('\"', '"', $_POST['p']);
>> $json=$post;
>> $d=json_decode($json,true);
>>
>> foreach($d as $key=>$val) { ...... do what you will with it after this
>> unless you know the key names !!
I totally do not understand what you are doing here. Could you explain
a little bit?
P.S. It is much easier to read posts if everyone would ansver below or
inline of the previous post, not "Top-Post". Just like T.J. Crowder did.
--
Best Regards,
SWilk