diff --git a/include/layout.inc b/include/layout.inc
index 2f3f8207a6..7f572da6bc 100644
--- a/include/layout.inc
+++ b/include/layout.inc
@@ -14,26 +14,33 @@ ini_set('highlight.keyword', 'keyword');
ini_set('highlight.string', 'string');
ini_set('highlight.html', 'html');
+// convert PHP 8.2 highlight_string() output to match PHP 8.3+
+function normalize_highlight_string(string $html): string
+{
+ $search = ["\r\n", "\n", '
', ' '];
+ $replace = ["\n", '', "\n", ' '];
+ $result = str_replace($search, $replace, $html);
+
+ // strip extra span tag
+ $result = substr_replace($result, '', 5, 6);
+ $result = substr_replace($result, '', -14, 7);
+
+ return '
' . $result . ''; +} + // Highlight PHP code function highlight_php($code, $return = false) { $highlighted = highlight_string($code, true); - // Use this ugly hack for now to avoid code snippets with bad syntax screwing up the highlighter - if (strstr($highlighted, "include/layout.inc")) { - $highlighted = '' . nl2br(htmlentities($code, ENT_HTML5), false) . ""; + if (PHP_VERSION_ID < 80300) { + $highlighted = normalize_highlight_string($highlighted); } - // Fix output to use CSS classes and wrap well - $highlighted = '
' . str_replace($search, $replace, $highlighted) . '