quocvuongdn icon

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

quocvuongdn | PRO | 03/03/15 01:38:47 AM UTC | 0 ⭐ | 476 👁️ | Never ⏰ | []
PHP |

270 B

|

None

|

0 👍

/

0 👎

function wrap_text($string = "") {
        //Replace all multiple new lines with one
        $string = preg_replace('"(\r?\n){2,}"', "\n\n", $string);
        //Replace multiple spaces, tabs with single space
        $string = preg_replace('"/(\t| ){2,}/"', "$1", $string);
        return $string;
    }

Comments