Jump to content

Replacing </br> with <p> tags from nl2br function


poleposters

Recommended Posts

Code:

<?php

function nl2p( $str ) {
$str = str_replace( array("\r\n", "\r"), "\n", $str );
return "<p>\n" . str_replace( "\n", "\n</p>\n<p>\n", $str ) . "\n</p>";
}

$html = <<<HTML
This is some text we want to convert
line
breaks
to paragraph
tags
HTML;

echo nl2p( $html );

?>

 

Output:

<p>
This is some text we want to convert
</p>
<p>
line
</p>
<p>
breaks
</p>
<p>
to paragraph
</p>
<p>
tags
</p>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.