Ethan Webster
Ethan Webster

Reputation: 93

Replacing a newline with a <br> - PHP

I'm guessing this is something you can do in PHP. What I want is to get the text in a textfield when the submit button is pressed and convert all the newlines into

<br>'s.

Help, please?

Upvotes: 1

Views: 251

Answers (2)

OMGKurtNilsen
OMGKurtNilsen

Reputation: 5098

This illustrates it better:

$str = "This is a
multiline
string";
echo nl2br($str);

Upvotes: 0

lonesomeday
lonesomeday

Reputation: 237847

nl2br would do what you want, I think.

<?php
$str = "\n\nfoo\nbar";
echo nl2br($str);

Output:

<br />
<br />
foo<br />

Upvotes: 5

Related Questions