In my web application, I create a formula
which uses a textarea
to take a list of IDs (in hex). The user have to separate them by pressing return
after entering every ID.
<label class="col-md-3 control-label" for="id_list">IDs: </label>
<div class="col-md-9>
<textarea class="form-control" id="id_list" name="id_list" required></textarea>
</div>
Then, I send this list to the server for processing (in PHP):
$id_list = trim($_POST['id_list'];
$id_array = explode(PHP_EOL, $id_list);
// file_put_contents('/tmp/bla.txt', $id_array);
for($i = 0; $i < count($id_array); $i++){
// Do stuff
}
// Now I want to save the ids in a string which will separate the ids with ","
$id_string = str_replace(PHP_EOL, ',', $id_list)
This works fine on a Windows server. However, on a Linux server it seems to have problem with PHP_EOL
; when I put the result from explode(PHP_EOL, $id_list)
in a txt file and examine it in Notepad++, the CR
is still there.
I tried different ways'\n','\r\n',...
, but it seems using PHP_EOL
is the only way where explode(PHP_EOL, $id_list)
works in Windows.
What can I do to make it working on both Windows AND Linux?