Advertisement
TonyAR

Add line breaks to specific lines only

Mar 27th, 2023
811
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | Source Code | 0 0
  1. function nl2pX($string) {
  2.         $paragraphs = "";
  3.         $pattern = array('<div class="row">', '<div>', '</div>', '<h1>', '</h1>', '<h2>', '</h2>', '<h3>', '</h3>', '<h4>', '</h4>', '<strong>', '</strong>', '<table class="center">', '<table>', '</table>', '<th>', '</th>', '<tr>', '</tr>', '<td>', '</td>', '<pre>', '</pre>', '<script>', '</script>', '<link>', '<code>', '</code>' );
  4.  
  5.         foreach (explode("\n", $string) as $line) {
  6.                 if (trim($line)) {
  7.                         $match = (str_replace($pattern, '', $line) != $line);
  8.                                 if ($match == "1") {
  9.                                         $paragraphs .= "{$line}\n";
  10.                                 } else {
  11.                                 $paragraphs .= "{$line}<br>\n";
  12.                                 }
  13.                         }
  14.                 }
  15.         return $paragraphs;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement