Reputation: 169
I'm adding text to MySQL database from textarea. All newlines are converted to \r\n I'm able to diplay new lines correcly in html by using below scipt:
function solver_nl2br($e){
$output = str_replace("\\r\\n", "<br/>", $e);
return $output;
}
But when I'm trying to edit text in textarea all I can see is \r\n
instead of new lines.
What function I can use to display new lines instead of new line characters in textarea?
Upvotes: 0
Views: 2432
Reputation: 7054
Use native function nl2br()
. It will catch more cases: (\r\n, \n\r, \n and \r). FYI: There are also constants for new lines PHP_EOL. You want your code to run well on Windows or Linux when possible.
Upvotes: 1