1

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.

P. Frank
  • 5,691
  • 6
  • 22
  • 50
Montezuma
  • 49
  • 2
  • 12

1 Answers1

2

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.

Tash Pemhiwa
  • 7,590
  • 4
  • 45
  • 49
  • The problem is, i am reading in csv files, so some of them end with /r some with /n and some with r/n/ so i dont want ajax to just send /n or /r, i want ajax not to change what i am sending, so that it dont change the line feed at the of the post data – Montezuma Oct 22 '15 at 07:27
  • I actually can do it the ugly way: check which line end the string has before i send it, and then replace the new line end after receiving with the old one. But i would prefere a more beautiful solution? – Montezuma Oct 22 '15 at 07:33
  • I will change the uploaded file with sed, can someone tell me how to sed from unix to dos, and from unix to unix format? sed -i 's/$/\r\n/' – Montezuma Oct 22 '15 at 09:16