A client of mine is using an old CMS and their database contains blog entries that used nl2br() on the frontend to give the illusion of paragraph spacing.
On the backend, there is a simple textarea that allows you to add text.
So for example if you add this:
First line<br>
Second line<br>
Third line<br>
It display like this on the frontend
First line
Second line
Third line
How can I look for this pattern with preg_replace so I can make it more like this on the database
<p>First line</p>
<p>Second line</p>
<p>Third line</p>
Thanks for any help you can provide!
Here's sample PHP that should do what you're looking for.
<?php
$string = <<<STRING
First line<br>
Second line<br>
Third line<br>
STRING;
$output = preg_replace("/^(.*)<br.*\/?>/m", '<p>$1</p>', $string);
echo $output;
?>
The output comes out as:
<p>First line</p>
<p>Second line</p>
<p>Third line</p>
Here's the regex if you want to play with it: https://regex101.com/r/zY6zO9/1