I have some paragraphs like this:
“This is the first para. r\r\n\n This
is the second one with lot of new line
after \n\n\n\n\n\n And the last para.
\n\r\r”
I want to remove the new lines and wrap each paragraph with the <p> tag. I’m expecting output as follows:
<p>This is the first para.</p>
<p>This is the second one with lot of new line after</p>
<p>And the last para.</p>
something like this perhaps?
If you find the line contains any new lines/carriage returns at the beginning or end, remember to call a
.trim()on the string first before replacing the values (using this example,d.trim().replace(...))More robust solution
PHP Version:
http://www.ideone.com/1TRhh