Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

How to fix preg_replace error in php7

How to fix old php code that no longer works in php7.
I know that preg_replace() was outdated and the /e modifier doesn't work anymore in php7.
Here is the old code:
$text = preg_replace('#\[url=([\r\n]*)([^\s\'\"]*?)\](.*?)([\r\n]*)\[/url\]#sie', "'<a href=\'".$pathto."'.base64_encode('http://\\2').'\' rel=\'nofollow\' target=\'_blank\' title=\'\\2\'>\\3</a>'", $text);

I am trying to fix it like this:
$text = preg_replace_callback('#\[url=([\r\n]*)([^\s\'\"]*?)\](.*?)([\r\n]*)\[/url\]#si', function ($m) use($pathto) {$link = $m[2]; return "<a href='$pathto".base64_encode('http://\\2').'\' rel='nofollow' target='_blank' title='$link'>"\\3</a>';}, $text);

My code is incorrect and causes an error.
I don’t know how to fix

As well as

Can someone give an example of fixing this code?
Basically, I want to understand the principle of link encryption using base64_encode, as well as how to use urlencode in php-fusion.
Now I'm trying to fix an old Polarfox mod http://unlogic.info/forum/viewthread....read_id=29 This mod no longer works in php7.
All popular cms have similar plugins for redirecting external links through the go.php page, with encoded links to remove htpps: // and domain_name.com
I just want to keep this mod in order to take the code as a basis in the future.
Now on the site, I use go.php made according to this instruction https://tutorialzine.com/2013/12/quic...nes-of-php
For future plans, I want to try to modify the go.php that I use. My task is to cut out htpps: // and domain_name.com in normal links for go.php without using the bbcode [url] and [img] tags.
The suggested options in this thread https://www.php-fusion.co.uk/infusion...d_id=40062 do not work for me.
Try this

$text = preg_replace('#\[url=([\r\n]*)([^\s\'\"]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\' title=\'\2\'>\3</a>', $text);

RobiNN, - Thank you for participating. I think I managed to fix the part of the code that is responsible for hiding http:// and encryption. There, small errors remain associated with different settings. I don’t need them yet, so I didn’t fix them.

Now I have a different question. How can I use this ... I need this encryption code for ad units. I'm a little at a loss. Need to think. Can you advise something.
Here is a sample code that I got in order to fix the deprecated preg_replace () function and / e modifier. Maybe someone will come in handy.
$text = preg_replace_callback(
 function ($m) use($pathto) {
 $link = $m[2].$m[3];
 return "<a href='$pathto"
 ."' rel='nofollow' target='_blank' title='$link'>"
 .trimlink($link, 20)
 .(strlen($link)>30?substr($link, strlen($link)-10, strlen($link)):'')

And here is the old code, for comparison.
$text = preg_replace('#\[url\]([\r\n]*)(http://|ftp://|https://|ftps://)([^\s\'\"]*?)([\r\n]*)\[/url\]#sie', "'<a href=\'".$pathto."'.base64_encode('\\2\\3').'\' rel=\'nofollow\' target=\'_blank\' title=\'\\2\\3\'>'.trimlink('\\2\\3', 20).(strlen('\\2\\3')>30?substr('\\2\\3', strlen('\\2\\3')-10, strlen('\\2\\3')):'').'</a>'", $text);

There are two more lines of code that are becoming outdated, and I don't know how to fix them.
$guest_msg = '[ link is hidden ] ( <a href=\''.BASEDIR.'register.php\'><u>registration</u></a> | <a href=\''.BASEDIR.'login.php\'><u>input</u></a> )';

$pathto = ($friendlyurl?BASEDIR.$friendlypath.'?':INCLUDES.'bbcodes/url_bbcode_include.php?');

I have a warning like this:


Warning: Use of undefined constant INCLUDES - assumed 'INCLUDES' (this will throw an Error in a future version of PHP)

If I understand correctly, I need to put quotation marks, but it doesn’t work out for me to do it correctly. Can you help?
Thread Information
6 posts
212 times
Last Post
Last updated on 1 month ago
You can view all discussion threads in this forum.
You cannot set up a bounty in this discussion thread.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
You cannot up or down-vote on the post in this discussion thread.
Users who participated in discussion: zizub, RobiNN