ggalan
09-15-2011, 04:46 PM
i have a textarea input field and when you hit the return key json_encode will output the actual break, not interpret it as \n or <br> like this. this line breaks my code
{"data":[
{"index":3,"text":"blue
","img":"blue.jpg"},
{"index":2,"text":"green","img":"green.jpg"},
{"index":1,"text":"something","img":"yellow.jpg"}
]}
i would like it to output like this
{"data":[
{"index":3,"text":"blue\n","img":"blue.jpg"},
{"index":2,"text":"green","img":"green.jpg"},
{"index":1,"text":"something","img":"yellow.jpg"}
]}
heres a truncated section of my code
<form id="itmSubmit" method="POST">
<textarea id="entryItm" name="entryItm" cols="50" rows="1" wrap="off"></textarea><br/>
<input class="itmSubmit" type="submit" value="enter" />
</form>
$nTitle = $_POST['entryItm']; // get posted comment
$dataArr = array('index' => $num++, 'text' => $nTitle, 'img' => 'blank.jpg');
array_unshift($dataList['data'], $dataArr);
$dataTxt = json_encode($dataList);
is there a way to output the enter key hit as \n in the json output?
{"data":[
{"index":3,"text":"blue
","img":"blue.jpg"},
{"index":2,"text":"green","img":"green.jpg"},
{"index":1,"text":"something","img":"yellow.jpg"}
]}
i would like it to output like this
{"data":[
{"index":3,"text":"blue\n","img":"blue.jpg"},
{"index":2,"text":"green","img":"green.jpg"},
{"index":1,"text":"something","img":"yellow.jpg"}
]}
heres a truncated section of my code
<form id="itmSubmit" method="POST">
<textarea id="entryItm" name="entryItm" cols="50" rows="1" wrap="off"></textarea><br/>
<input class="itmSubmit" type="submit" value="enter" />
</form>
$nTitle = $_POST['entryItm']; // get posted comment
$dataArr = array('index' => $num++, 'text' => $nTitle, 'img' => 'blank.jpg');
array_unshift($dataList['data'], $dataArr);
$dataTxt = json_encode($dataList);
is there a way to output the enter key hit as \n in the json output?