Solver
Solver

Reputation: 169

How to display new lines in textarea?

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

Answers (3)

FirmView
FirmView

Reputation: 3150

try this,

  $output = nl2br(htmlenitites($e));

Upvotes: 2

ficuscr
ficuscr

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

Farnabaz
Farnabaz

Reputation: 4066

try this:

$output = str_replace("\\r\\n", "\n", $e);

Upvotes: 0

Related Questions