Jump to content
Latest News: (loading..)

Recommended Posts

since regex and stuff is a book of seven seals to me, i would need some help to bring those two lines to php7.0

it should be transformed into preg_replace_callback because of the e modifier, but i dont understand how this preg_replace_callback works.

Can someone help and transform those lines for me? Thanks alot!

        $text = preg_replace("#\{\{((STORE_|OWNER_|EMAIL_)[A-Z0-9_]+)\}\}#e", '$1', $text);

        $email_subject = preg_replace("#\{\{((STORE_|OWNER_|EMAIL_)[A-Z0-9_]+)\}\}#e", '$1', $email_subject);


Need an easy base to start creating Oscommerce Modules?
https://oscompose.com/ (Forum Thread about OsCompose)

 

Share this post


Link to post
Share on other sites
Posted (edited)

Not knowing the full code for the function, Please make sure you back up before doing this! Not a PHP expert but try this for first line and see what error you get.

$text = preg_replace_callback("#\{\{((STORE_|OWNER_|EMAIL_)[A-Z0-9_]+)\}\}#", function ($matches) {return '$1'($matches['$1']); }, $text);

Edited by JcMagpie

I'm using the cutting Edge v2.3.4.1 CE:thumbsup::smile:

Get the latest osCommerce Online Merchant Community Bootstrap Edition v2.3.4.1 CE

 

Share this post


Link to post
Share on other sites

Ok but that is something else as i do not get that when testing just that line in PHP sand box. What is the full function? Or better still you can test in sand box and see.

http://sandbox.onlinephpfunctions.com/


I'm using the cutting Edge v2.3.4.1 CE:thumbsup::smile:

Get the latest osCommerce Online Merchant Community Bootstrap Edition v2.3.4.1 CE

 

Share this post


Link to post
Share on other sites

it sounds like it is explained here realy nicely, but i still dont get how to transform those 2 lines. :sad:

https://stackoverflow.com/questions/15454220/replace-preg-replace-e-modifier-with-preg-replace-callback#15454454


Need an easy base to start creating Oscommerce Modules?
https://oscompose.com/ (Forum Thread about OsCompose)

 

Share this post


Link to post
Share on other sites
Posted (edited)

Check your work carefully that you did not accidentally insert an extra ( or drop a needed ). It's easy to mistake a { for a (, or vice-versa, when reading code.

May I ask what sort of project you're doing? If you're trying to convert an old add-on to PHP 7 compatibility, that's one thing, but if you have an old osC (anything pre-2.3.4BS Edge) it's frankly not a good use of your time to try upgrading old code to work with PHP 7. You'd be much better off installing "Edge" (see link below in my signature) and migrating your data over. You'll have PHP 7.1 compatibility, lots of new features and bug fixes, and best of all it's mobile-friendly (responsive).

Edited by MrPhil

If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites
Posted (edited)

the way the original preg_replace was coded was to replace {{STORE_OWNER}} etc with defined constants (its all in a payment module). so, this works now. i hope this is usefull to someone someday.
and please if you are asked if you can fix a small thing on an old car, dont try to sell a new car if you can just help with the problem. maybe i already have a new car, but still want to drive around a little longer with my old car as well. yes i know, the new car is the real deal! ;)

thank you @JcMagpie for your feedback/help!

 $text = preg_replace_callback(
    "#\{\{((STORE_|OWNER_|EMAIL_)[A-Z0-9_]+)\}\}#",
        function ($matches) {
            return constant($matches[1]);
        },
        $text
    );

another one that i have hopefully changed the right way in a helper function of this payment module is this one

        //$historyComments['seller'] = preg_replace('#\{\{([a-zA-Z0-9_]+)\}\}#e', '$$1', $historyComments['seller']);
        $historyComments['seller'] = preg_replace_callback(
        '#\{\{([a-zA-Z0-9_]+)\}\}#',
            function ($matches) {
            return ('$$matches[1]');
            },
        $historyComments['seller']
        );
Edited by Stephan Gebbers

Need an easy base to start creating Oscommerce Modules?
https://oscompose.com/ (Forum Thread about OsCompose)

 

Share this post


Link to post
Share on other sites
5 hours ago, Stephan Gebbers said:

the way the original preg_replace was coded was to replace {{STORE_OWNER}} etc with defined constants (its all in a payment module). so, this works now. i hope this is usefull to someone someday.
and please if you are asked if you can fix a small thing on an old car, dont try to sell a new car if you can just help with the problem. maybe i already have a new car, but still want to drive around a little longer with my old car as well. yes i know, the new car is the real deal! ;)

thank you @JcMagpie for your feedback/help!


 $text = preg_replace_callback(
    "#\{\{((STORE_|OWNER_|EMAIL_)[A-Z0-9_]+)\}\}#",
        function ($matches) {
            return constant($matches[1]);
        },
        $text
    );

another one that i have hopefully changed the right way in a helper function of this payment module is this one


        //$historyComments['seller'] = preg_replace('#\{\{([a-zA-Z0-9_]+)\}\}#e', '$$1', $historyComments['seller']);
        $historyComments['seller'] = preg_replace_callback(
        '#\{\{([a-zA-Z0-9_]+)\}\}#',
            function ($matches) {
            return ('$$matches[1]');
            },
        $historyComments['seller']
        );

Yes looks fine did not show any errors when I tested.:thumbsup:


I'm using the cutting Edge v2.3.4.1 CE:thumbsup::smile:

Get the latest osCommerce Online Merchant Community Bootstrap Edition v2.3.4.1 CE

 

Share this post


Link to post
Share on other sites

and please if you are asked if you can fix a small thing on an old car, dont try to sell a new car if you can just help with the problem. maybe i already have a new car, but still want to drive around a little longer with my old car as well. yes i know, the new car is the real deal! ;)

If you are trying to fix a broken headlamp on your old clunker, sure I'll be happy to give help. However, if you're trying to rebuild the engine of your daily driver one piece at a time by trial and error until it (sort of) runs, you'd be much better off with something new(er). You never said what you were trying to do, but it sure sounds like you're trying to do a major fix on old code, which as I said, will not be a productive use of your time. An old car is still compatible with the current highway system. An old application is no longer compatible with current servers. I can understand a sentimental attachment to a '65 Mustang; I can't understand keeping around osC 2.2. Your call.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

Just found this thread here. I need to get the following code up to date since it doesn't work in PHP 7 anymore.
Getting this error message:

Quote

Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead

I know that #se in the code below is the /e modifier and that's about it with my understanding.
Most support solutions I found on stackoverflow talkj about simple preg_replace cases but the following is a bit harder I think.

function tsimi ($text, $token, $class) {
$text = str_replace('\"', '"', substr(preg_replace('#(\>(((?>([^><]+|(?R)))*)\<))#se', "preg_replace('#\b(" . $token . ")\b#i', '<span class=\"" . $class . "\">\\\\1</span>', '\\0')", '>' . $text . '<'), 1, -1));
return $text;
}

Anyone out there can help getting this updated to a preg_replace_callback?

Thanks


When you ask for help/support:

  • Always state your osCommerce version
  • If possible, list up installed add-ons
  • 3rd party templates are not supported in the forum

Latest osC: osCommerce CE (Community Edition aka. v2.3.4.1 Frozen)

 

Share this post


Link to post
Share on other sites

Doing a search ("all topics") on preg_replace_callback gave me 17 hits just on this forum. Were none of those sufficient? If not, I'm sure StackOverflow, among others (via Google), has a ton of suggestions. I'm not sure this is something that you can mechanically perform (i.e., it requires some understanding of what was being done before), but it should be reasonably straightforward.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×