public static function escapeHtmlComment($s) { $s = (string) $s; if ($s && ($s[0] === '-' || $s[0] === '>' || $s[0] === '!')) { $s = ' ' . $s; } $s = str_replace('--', '- - ', $s); if (substr($s, -1) === '-') { $s .= ' '; } return $s; }