Remove all the line breaks from the html source Remove all the line breaks from the html source php php

Remove all the line breaks from the html source


Maybe this?

$output = str_replace(array("\r\n", "\r"), "\n", $output);$lines = explode("\n", $output);$new_lines = array();foreach ($lines as $i => $line) {    if(!empty($line))        $new_lines[] = trim($line);}echo implode($new_lines);


You can try this perhaps.

// Before any outputob_start();// End of file$output = ob_get_clean();echo preg_replace('/^\s+|\n|\r|\s+$/m', '', $output);

This should, unless I messed up the regex, catch all output, and then replace all new line characters as well as all whitespace at the end and beginning of lines.

If you already have all output collected in a variable, you can of course just use the last line directly and skip the output buffering stuff :)


Worked for me:

$output = str_replace(array("\r\n", "\r", "\n"), "", $output);