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.
Not a member yet? Click here to register.
Forgot Password?

How to fix preg_replace error in php7

Asked Modified Viewed 1,257 times
Z
zizub
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
  • Started this discussions
asked
Member

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
'http://\\2').'\'
As well as
\\3</a>

Can someone give an example of fixing this code?
0 replies

5 posts

R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

I assume you're trying to fix v7 on PHP 7. I don't recommend it. But okay, you can use code from v8 https://github.com/PHPFusion/PHPFusio...nclude.php, this code should also work in v7.
0 replies
Z
zizub
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
  • Started this discussions
answered
Member

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.
Edited by zizub on 01-06-2020 11:45,
0 replies
R
Anonymous User
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions
answered
Veteran Member

Try this

$text = preg_replace('#\[url=([\r\n]*)([^\s\'\"]*?)\](.*?)([\r\n]*)\[/url\]#si', '<a href=\'http://\2\' target=\'_blank\' title=\'\2\'>\3</a>', $text);
0 replies
Z
zizub
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
  • Started this discussions
answered
Member

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.
Edited by zizub on 03-06-2020 02:02,
0 replies
Z
zizub
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
  • Started this discussions
answered
Member

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(
 '#\[url\]([\r\n]*)(http://|ftp://|https://|ftps://)([^\s\'\"]*?)([\r\n]*)\[/url\]#si',
 function ($m) use($pathto) {
 $link = $m[2].$m[3];
 return "<a href='$pathto"
 .base64_encode($link)
 ."' rel='nofollow' target='_blank' title='$link'>"
 .trimlink($link, 20)
 .(strlen($link)>30?substr($link, strlen($link)-10, strlen($link)):'')
 .'</a>';
 },
 $text
);

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:

Quote

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?
Edited by zizub on 04-06-2020 03:59,
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 5 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

Z
Z
zizub 10
  • Member, joined since
  • Contributed 156 posts on the community forums.
  • Started 29 threads in the forums
  • Started this discussions
R
R
Anonymous User 367
  • Veteran Member, joined since
  • Contributed 939 posts on the community forums.
  • Started 2 threads in the forums
  • Answered 20 questions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet