Writing a string array to text file separated by new line character

后端 未结 3 1317
挽巷
挽巷 2021-01-03 07:38

I have a PHP page which accepts input from user in a text area. Multiple strings are accepted as input from user & would contain \'\\n\' and I am scanning it as:

3条回答
  •  旧时难觅i
    2021-01-03 08:22

    If you want to add new lines, then why are you first removing them?

    $data = explode("\n", $_GET['TxtareaInput']);
    

    Keep only this line:

    fwrite($ourFileHandle, $data);
    

    It will write your data to the file as it was received.

    If you want to replace all new lines by carriage returns before writing to file, use this code:

        fwrite($ourFileHandle, str_replace("\n", "\r", $data));
    

提交回复
热议问题