I have some chunks of HTML in my database that I put in a JSON this way, upon first page render:
foreach ($data as $key => $value) {
$output .= '
"'.$key.'" : "'.addSlashes($value).'",
';
}
usually it works fine, except in a few cases where I get a leading line feed like this below:
"html" : "
<div id=\"object_01\" class=\"object_textbox\" namn=\"object_01\" style=\"z-index:1;font-family:Arial;left:750.9776000976563px;top:30.979339599609375px;position:absolute;width:709.6444444656372px;height:327.6444444656372px;\"><div class=\"object_inner\" style=\"border:0px solid rgb(0,0,0);background-color:rgb(255,255,255);color:rgb(0,0,0);opacity:.8;font-size:28px;line-height:42px;padding:20px;\">“Behold my Beloved Son, in whom I am well pleased, in whom I have glorified my name—hear ye him.” And it came to pass, as they understood they cast their eyes up again towards heaven; and behold, they saw a Man descending out of heaven; and he was clothed in a white robe; and he came down and stood in the midst of them...</div></div><div id=\"object_02\" class=\"object_textbox\" namn=\"object_02\" style=\"z-index:2;font-family:Arial;position:absolute;top:309.9988098144531px;left:1269.9826049804688px;width:187.6444444656372px;height:48.64444446563721px;\"><div class=\"object_inner\" style=\"border:0px solid rgb(0,0,0);font-style:italic;font-weight:bold;\">3 Nephi 11:7-8</div></div>",
Which obviously breaks the entiry page since javascript doesn't support linefeeds inside strings.
Any idéa what might cause it, or a way around it?
All the data from the database is picked up from a page at form save, so the user never gets to manually insert that linefeed... I just use jQuery element.html() to pick it up so there shouldn't be a linefeed there...
json_encodeinstead.