BUG: wrong tab handling in highlight_php_code function on PHP 5 server

Started by Gianni_T, January 20, 2005, 08:01:26 AM

Previous topic - Next topic

Gianni_T

First of all sorry for my english.
The function highlight_php_code( in Subs.php at line 1138) use the following preg_replace:

$buffer = preg_replace('~SMF_TAB(</font><font color="[^"]*?">)?\(\);~', "<pre style=\"display: inline;\">\t</pre>", $buffer);

The pattern used works in PHP 4 but is wrong in PHP 5 because the new release of PHP uses span tags and style attribute to highlight php code. For example:

<span style="color: rgb(0, 119, 0);">();</span>


Gianni_T

a solution may be:


<?php
if ((float) PHP_VERSION >= 5)
$buffer = preg_replace('~SMF_TAB(</span><span style="[^"]*?">)?\(\);~', "<pre style=\"display: inline;\">\t</pre>", $buffer);
else
$buffer = preg_replace('~SMF_TAB(</font><font color="[^"]*?">)?\(\);~', "<pre style=\"display: inline;\">\t</pre>", $buffer);
?>

[Unknown]

 ! Keep tabs in PHP code blocks properly under PHP 5. (Subs.php)

-[Unknown]

Gianni_T

I'm using PHP 5.0.2

In the following screenshot you can see how SMF handle tab:



<span style=".."> instead of <font ...>


More detail here

[Unknown]

Quote from: [Unknown] on January 21, 2005, 04:53:47 AM
! Keep tabs in PHP code blocks properly under PHP 5. (Subs.php)

-[Unknown]

This means I fixed it.

-[Unknown]

Advertisement: