PHP add paragraphs



  • Let's say there's a line where there's a text in front of a prisoner in the shadows and no:

    раз два 
    <p>три  <a href='#'>четыре</a> пять</p> 
    <img src="#">шесть <strong>семь</strong>
    <p>восемь</p>
    девять десять
    

    Maybe who has an example of how the entire text of a non-inmate in p is to conclude:

    <p>раз два</p>
    <p>три  <a href='#'>четыре</a> пять</p> 
    <p><img src="#">шесть <strong>семь</strong></p>
    <p>восемь</p>
    <p>девять десять</p>
    

    The text is organized without the symbols of the line translation.

    Examples https://stackoverflow.com/questions/5961217/how-do-i-surround-all-text-pieces-with-paragraph-tags?answertab=active#tab-top (nl2p_html) but he eats all the tales.



  • Something like that:

    $pattern = '/(^|<\\/[^>]*p>)(.*)(<[^>]*p>|$)/isU';
    $replacement = '$1<p>$2</p>$3';
    $subject = 'ваша строка';
    echo preg_replace($pattern, $replacement, $subject, -1 );
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2