I want to send something from one php site to another. At the first site, everything seems fine. The string seems like
--show="author,book,text/n
but when i check the string after receiving it looks like
--show="author,book,text/r/n
there is the problem, somehow it adds /r
in the end.
First php:
$(document).ready(function() {
$("#column_button").click(function(){
var selected = [];
$.each($("input[name='checkbox_columns']:checked"), function(){
selected.push($(this).val());
});
var data = new FormData();
data.append("data", "--show=" + selected);
//alert(JSON.stringify(selected));
var ajax = (window.XMLHttpRequest) ? new XMLHttpRequest() : new activeXObject("Microsoft.XMLHTTP");
ajax.addEventListener("load", statusHandler2, false);
ajax.open( 'post', 'showParameter.php', true );
ajax.send(data);
_("column_button").disabled=true;
});
});
Second php:
if(!empty($_POST['data'])){
$data = $_POST['data'];}
So selected shows it right, but if i check the $data in the second php, it's wrong.
This appears to be an issue where the servers are using different line ending types. Unix systems (Linux, BSD, etc) use \n
(LF
) by default, MacOS uses \r
(CR
) where as Windows systems use \r\n
(also known as CRLF
). You may need to change your character encoding on one of the servers to the other.
CR
= carriage return
LF
= line feed
You could use code that will substitute the CRLF or CR with just an LF. This page shows how you can achieve this simply.