Is there a function in PHP that can convert ENTER inputs from a textarea into different characters before writing to a file, similar to \n?

To convert ENTER inputs from a textarea into different characters before writing to a file in PHP, you can use the str_replace function to replace the ENTER character with the desired character (e.g., "\n"). This will ensure that the line breaks are preserved when writing to a file.

// Get the input from the textarea
$input = $_POST['textarea_input'];

// Replace ENTER inputs with '\n'
$input = str_replace("\r\n", "\n", $input);

// Write the modified input to a file
$file = fopen("output.txt", "w");
fwrite($file, $input);
fclose($file);