Search code examples
phpparagraph

nl2br for paragraphs


$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>

Solution

  • Try this:

    $variable = str_replace("\n", "</p>\n<p>", '<p>'.$variable.'</p>');