2026-05-27, 04:18 PM
(This post was last modified: 2026-05-27, 04:19 PM by PARADOX987. Edited 1 time in total.)
File: inc/class_parser.php
The Bug:
In PHP 8.3, the internal output of the native
longer generates the exact same <span style="color: ..."> and <code> HTML structure as older
PHP versions.
Because
HTML structure, these regex replacements now create broken/unbalanced HTML tags. At the end of
the parsing process, MyBB's
HTML and completely abort, returning an empty string.
The Code Causing It (inc/class_parser.php inside
The Fix:
Update the string replacement logic in
Find this block in inc/class_parser.php:
Replace with:
The Bug:
In PHP 8.3, the internal output of the native
highlight_string() function was changed. It nolonger generates the exact same <span style="color: ..."> and <code> HTML structure as older
PHP versions.
Because
mycode_parse_php() uses hardcoded preg_replace patterns that expect the old PHP 8.2-HTML structure, these regex replacements now create broken/unbalanced HTML tags. At the end of
the parsing process, MyBB's
output_allowed() and validate_output() methods detect this invalidHTML and completely abort, returning an empty string.
The Code Causing It (inc/class_parser.php inside
mycode_parse_php):1 $code = @highlight_string($str, true);
2
3 // These replacements fail to correctly balance tags on PHP 8.3+
4 $code = preg_replace('#<pre><code style="color: \#000000">#i', "<code>", $code);
5 $code = preg_replace('#<code>\s*<span style="color: \#000000">\s*#i', "<code>", $code);
6 $code = preg_replace("#</span>\s*</code>#", "</code>", $code);
7 $code = preg_replace("#</code>\s*</pre>#", "</code>", $code);
8 $code = preg_replace("#</span>(\r\n?|\n?)</code>#", "</span></code>", $code); The Fix:
Update the string replacement logic in
mycode_parse_php() to account for PHP 8.3+'s modernhighlight_string() wrapper format.Find this block in inc/class_parser.php:
1 if($added_end_tag)
2 {
3 $code = str_replace("?></span></code>", "</span></code>", $code);
4 // Wait a minute. It fails highlighting? Stupid highlighter.
5 $code = str_replace("?></code>", "</code>", $code);
6 }
7
8 $code = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "",
$code);
9 $code = str_replace("<code>", "<div dir=\"ltr\"><code>", $code);
10 $code = str_replace("</code>", "</code></div>", $code);Replace with:
1 if($added_end_tag)
2 {
3 $code = str_replace("?></span></code>", "</span></code>", $code);
4 $code = str_replace("?></code>", "</code>", $code);
5 $code = str_replace("?></span></pre>", "</span></pre>", $code);
6 }
7
8 $code = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "",
$code);
9
10 // PHP 8.3+ compatibility: remove stray wrapping <pre> tags leftover from new
highlight_string format
11 $code = str_replace("<pre>", "", $code);
12 $code = str_replace("</pre>", "", $code);
13
14 $code = str_replace("<code>", "<div dir=\"ltr\"><code>", $code);
15 $code = str_replace("</code>", "</code></div>", $code);