tags:

views:

139

answers:

1

Well the question title explains the question :D but here is an example none the less

asdf
asdf
<p>asdf
asdf
asdf</p>

how to i get it to regex the inside of the p tags and apply nl2br to it so the output would be:

asdf
asdf
<p>asdf<br />
asdf<br />
asdf</p>

Edit: In PHP

+3  A: 

Use Simple HTML DOM rather than regex

$html = str_get_html(...);

foreach($html->find('p') as $element){
    //get html in p
    $ihtml = p->innertext;

    //apply function
    $ihtml = nl2br($ihtml);

    //save
    $p->innertext = $ihtml;
}

//print the new output
echo $html;
Yacoby
Thanks Bro, Appreciate it
Shahmir Javaid