Now I googled a bit and could not find anything that may helps me so I decided to ask you.
I have a script that collects Data from a form. Source is not needed.
There is also a <textarea id="sample"></textarea>
where some content gets written in. In my jQuery is use following Line:
$(document).ready(function(){
var cData = {};
var url = 'http://www.sample.xy/samplefolder/index.php?cData=';
$('#submit_btn').on('click', function(){
//here are some more fields
//...
cData.text = $('#sample').val();
}
var bCode = btoa('{"field_one":"' + cData.field_one + '", "text":"' + cData.text + '"}');
//sending the data...
window.open(url + bCode, '_blank');
});
Actually this all works fine. But on the PHP side I run into json problems.
btoa
transforms my content into a base64 string. My PHP source looks like
$data = base64_decode( $_GET['cData'] ) ;
What brings me the expacted string
{"field_one":"i am field one","text":"I am a text over
multiple rows
and this makes me
not valid for json"}
As you may noticed in the content of text
, multirow causes the json validate of json_decode( ... )
to fail.
So my question is, how can I get the multi row valid for json without losing the linebreaks? Because I need them as they are. Because I want to use the content to create a PDF file with FPDF. So filling in <br />
doesn't really helps.
I tried json_encode
before json_decode
what just retuned my a null
:/