public function output() {
if ($this->output) {
#start
$_regex_scripts = '/<script[^>]*>(.*?)<\/script>/s';
$_regex_paste_position = '/<\/body>/';
preg_match_all($_regex_scripts, $this->output, $all_scripts, PREG_SET_ORDER);
$this->output = preg_replace($_regex_scripts, '', $this->output);
$scripts = '</body>';
foreach ($all_scripts as $key => $value) {
$scripts .= $value[0].PHP_EOL;
}
$this->output = preg_replace($_regex_paste_position, $scripts, $this->output);
#end
if ($this->level) {
$output = $this->compress($this->output, $this->level);
} else {
$output = $this->output;
}
if (!headers_sent()) {
foreach ($this->headers as $header) {
header($header, true);
}
}
echo $output;
}