0

I'm in the process of updating a Magento site and ran into a error that is causing me to delay pushing this to live.

PHP error:

PHP Deprecated:  preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /skin/frontend/default/galadrugstore/css/style.php on line 62

Style.php line 62:

$content = preg_replace('/\$([\w]+)/e','$0',@file_get_contents($stylesheet));

I have tried the following with out any traction, as a last resort I wanted to see if someone could assist before I lose my mine.. lol

$content = preg_replace_callback('/\$([\w]+)', function($match) { return CallFunction($match[0]); }, @file_get_contents($stylesheet)); 
$content = preg_replace_callback('/\$([\w]+)/', function($match) { return CallFunction($match[0]); }, @file_get_contents($stylesheet));
$content = preg_replace_callback('/\$([\w]+)/', function($match) { return $match[0]; }, @file_get_contents($stylesheet));

I feel I'm really close but something is just not right, any assistance with this issue would be awesome.

Big Thanks in Advance!

  • how did you solve it finally ? – Kishore Patra Mar 21 '16 at 7:23
1

The e modifier is short for eval. It performs a back reference substitution, then executes the replacement string as PHP, then performs the substitution using the returned value.

For example:

$pattern     = '/(.*)/e';
$replacement = 'strtoupper("$0");';
$input       = 'hello';
echo preg_replace($pattern, $replacement, $input);

Can be translated into:

$pattern     = '/(.*)/';
$input       = 'hello';
echo preg_replace_callback($pattern, function ($matches) {
    return strtoupper($matches[0]);
}, $input);

Without knowing what's returned by @file_get_contents($stylesheet) it's a little difficult to give accurate advice. The most obvious answer is the following, however be warned, this is pretty much as insecure as the e modifier (which is why it's deprecated):

echo preg_replace_callback('/\$([\w]+)/', function ($matches) {
    return eval($matches[0]);
}, $input);
  • @file_get_contents($stylesheet) returns stylesheet overrides, this file or part of the file takes css styles from the db and loads them into a custom style sheet. – WadeO Feb 10 '16 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.