Stephan Gebbers Posted May 21, 2018 Share Posted May 21, 2018 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); Link to comment Share on other sites More sharing options...
♥JcMagpie Posted May 22, 2018 Share Posted May 22, 2018 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); Link to comment Share on other sites More sharing options...
Stephan Gebbers Posted May 22, 2018 Author Share Posted May 22, 2018 PHP Parse error: syntax error, unexpected '(' Link to comment Share on other sites More sharing options...
♥JcMagpie Posted May 22, 2018 Share Posted May 22, 2018 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/ Link to comment Share on other sites More sharing options...
Stephan Gebbers Posted May 22, 2018 Author Share Posted May 22, 2018 it sounds like it is explained here realy nicely, but i still dont get how to transform those 2 lines. https://stackoverflow.com/questions/15454220/replace-preg-replace-e-modifier-with-preg-replace-callback#15454454 Link to comment Share on other sites More sharing options...
♥JcMagpie Posted May 22, 2018 Share Posted May 22, 2018 Test in the sandbox and see what you get, as I do not get that error. Link to comment Share on other sites More sharing options...
MrPhil Posted May 23, 2018 Share Posted May 23, 2018 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). Link to comment Share on other sites More sharing options...
Stephan Gebbers Posted May 24, 2018 Author Share Posted May 24, 2018 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'] ); Link to comment Share on other sites More sharing options...
♥JcMagpie Posted May 24, 2018 Share Posted May 24, 2018 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. Link to comment Share on other sites More sharing options...
MrPhil Posted May 24, 2018 Share Posted May 24, 2018 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. Link to comment Share on other sites More sharing options...
♥Tsimi Posted June 12, 2018 Share Posted June 12, 2018 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 Link to comment Share on other sites More sharing options...
MrPhil Posted June 15, 2018 Share Posted June 15, 2018 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.