Forum Moderators: coopster

Message Too Old, No Replies

How to rewrite / migrate "create function" for PHP 8?

Trying to fix old forum software

         

MichaelBluejay

1:31 am on Nov 3, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I run a small forum as a volunteer project using old forum software (FluxBB) which seems to not be supported any more. (Their website returns "server not found".)

My webhost asked me to upgrade my PHP to v8.0 and I did, but that broke the forum software. I don't know much PHP, but I was able to fix most of the problems, however I'm stuck on this one. create_function has been removed from PHP and I don't know how to code around that, where the script is using it to convert BBcode to HTML, using an array of patterns and an array of replacements. It's not throwing any errors, but the loop runs only twice when it's supposed to run a bunch of times, and during those two times it doesn't perform the replacement. Here's the problem code:

Here's one such offending line:

$pattern_callback[] = '%\[url\]([^\[]*?)\[/url\]%';
$pattern_callback[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%';
$pattern[] = '%\[email\]([^\[]*?)\[/email\]%';
$pattern[] = '%\[email=([^\[]+?)\](.*?)\[/email\]%';
/* And nine more array values defined here, as well as the replacements */

$count = count($pattern_callback);
for($i = 0 ; $i < $count ; $i++)
{
$text = preg_replace_callback($pattern_callback[$i], create_function('$matches', 'return '.$replace_callback[$i].';'), $text);
}

I tried replacing the "$text=..." line with this:
$fixFunction = 
function($matches) {
return $replace_callback[$i];
};

$text =
preg_replace_callback
(
$pattern_callback[$i],
$fixFunction,
$text
);


Can anyone help with this?

MichaelBluejay

4:41 am on Nov 3, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, it turns out that someone took it upon himself to update the software, so if anyone else is trying to get FluxBB to run with PHP 8, then here you go [github.com].

It didn't recognize my old database, I had to copy all the data from the old one into the new one, and I also had to run the db_update.php script that comes with the forum software.