-1

i have a varible like so:

$Text= "Hello 
        My 
        Code"

so what i want to happen is where ever there is a new line to insert
so it should look like

$NewText = "Hello<br>
            My<br> 
            Code"

*

c319113
  • 215
  • 1
  • 3
  • 11

1 Answers1

2

You can use nl2br, preg_replace or str_replace:

$text = "Hello\nMy\nCode";

$newText = nl2br($text);

$newText = preg_replace('/\r?\n/', "<br>\n", $text);

$newText = str_replace("\n", "<br>\n", $text);
jspcal
  • 50,847
  • 7
  • 72
  • 76