Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nl2br for paragraphs

Tags:

php

paragraph

$variable = 'Afrikaans 
Shqip - Albanian  
Euskara - Basque';

How do I convert each new line to paragraph?

$variable should become:

<p>Afrikaans</p>
<p>Shqip - Albanian</p>
<p>Euskara - Basque</p>
like image 922
James Avatar asked Nov 29 '22 04:11

James


1 Answers

Try this:

$variable = str_replace("\n", "</p>\n<p>", '<p>'.$variable.'</p>');
like image 199
Tim Fountain Avatar answered Nov 30 '22 17:11

Tim Fountain