editor.getValue() in this case is a codemirror instantiation. I’m not sure if this complicates matters further. The reason for using encodeURIComponent was to properly send linebreaks over GET. This appears to work, but on the PHP side:
There’s a note on the documentation page for php urldecode() that says:
"Warning : The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results. "
That suggests to me that you should drop the urldecode() from the code.
As @droopsnoot mentioned, all input superglobals in PHP are already url decoded so you don’t have to do it yourself, however in most cases when you use urldecode() - that is decode the value twice - the string will be the same. Sometimes, depending on the contents, it can be different so you should definitely get rid of urldecode() in your PHP code.
Yes, this seems to be correct as you wrote you were getting this:
\n for line breaks is not url encoding, url encoding is done with the percent sign and a hexadecimal code value so urldecode() is not going to help you. This looks like javascript string escaping so you should be fine using a function that will simply replace the escaped sequences with actual characters: