So the function nl2br is handy. Except in my web app, I want to do the opposite, interpret line breaks as new lines, since they will be echoed into a pre-filled form.
<
If whitespaces are stripped out before outputting the html (for minification), "\n"
, "\r"
, PHP_EOL
, etc. will get stripped out. ASCII encoding will survive the stripping process.
function minify($buffer) {
return preg_replace('/\s\s+/', ' ', preg_replace('~>\s+<~', '><', $buffer));
}
ob_start('minify');
...
$nl = preg_replace('/\
/i', "
", $br);
echo "";
...
ob_get_flush();