/** * @param string * @param string * @return TranscodeMessage[] */ public static function optimizeHTML(&$html, $outFile = null) { $writeFile = true; if ($outFile === null) { $outFile = File::createTempFile()->getPath(); $writeFile = false; } # tidy $msgs = self::tidy($html, $outFile); # PHP syntax check $msgs = array_merge($msgs, self::checkPHPSyntax($outFile)); # remove redundant spaces/linebreaks $trans = array('/<\\?[\\s\\n\\r]*\\/\\*.+\\*\\/[\\s\\n\\r]*\\?>/Ums' => '', '/<!--(.+)-->/Ums' => '', '/>[\\r\\n\\s\\t]+</m' => '><'); $html = preg_replace(array_keys($trans), $trans, $html); # write file if ($writeFile) { file_put_contents($outFile, $html); } return $msgs; }