quocvuongdn

#php: Replace all multiple newlines with one. multiple space

Mar 2nd, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.27 KB | None | 0 0
  1. function wrap_text($string = "") {
  2.         //Replace all multiple new lines with one
  3.         $string = preg_replace('"(\r?\n){2,}"', "\n\n", $string);
  4.         //Replace multiple spaces, tabs with single space
  5.         $string = preg_replace('"/(\t| ){2,}/"', "$1", $string);
  6.         return $string;
  7.     }
Advertisement
Add Comment
Please, Sign In to add comment