Regex to find text outside HTML tags and then replace <br> tag with <p> using PHP -


i'm using html5 wysiwyg editor doesn't seem insert paragraph tags automatically. insert br , h1, h2, etc. basic example of text generated looked this:

<h1>this header</h1>this should stand alone paragraph<br><br>this paragraph   should split<br>into 2 lines. 

i know if it's possible take not within open , closing tag , put in paragraph, , replace double br </p> <p> generate this:

<h1>this header</h1><p>this should stand alone paragraph</p><p>this paragraph should split<br>into 2 lines.</p> 

thanks in advance help.

as long input text has same structure 1 provided example: <h1>this header</h1>this should stand alone paragraph<br><br>this paragraph should split<br>into 2 lines.

then, can use regex:

^(.*<\/h1>)([^<]+)(<br>\s*<br>)(.*)$ 

and replace as: \1<p>\2</p><p>\4</p>

here's working demo


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -