Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/15/2022 in all areas

  1. The original line was $V341be97d = preg_replace('/\^([^\^<])/e', "'`' . \$V70dda5df[ord('\\1') % 8]", $V341be97d); That was updating $V341be97d, on the left-hand side of the = assignment, with a new value coming from preg_replace. Your updated version preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d); changed the preg_replace into a preg_replace_callback but it lost the $V341be97d= that was there before. Still need it, otherwise whatever this replacement was designed to handle (namely the ^0s and ^7s and such that you're now seeing) won't happen.
    1 point
  2. It's a shame the code is open-source but extremely unreadable... I'll use those two as an example. Moving away from /e goes basically like: 1. Switch the function to preg_replace_callback and drop the /e flag, obviously. 2. Change the second argument (a string) to be a function following the template function($matches) { return ___; } where you put in there the replacement string but minus the outer quotes. 3. Replace "\\1" with $matches[1], "\\2" with $matches[2], and so on, and correct any issues with the PHP syntax. So this preg_replace("/\+([\x01-\x7F])#/e", "chr(ord('\\1') + 127)", $V341be97d) starts as preg_replace_callback("/\+([\x01-\x7F])#/", function($matches) { return chr(ord('\\1') + 127); }, $V341be97d) and you replace the '\\1' string to get preg_replace_callback("/\+([\x01-\x7F])#/", function($matches) { return chr(ord($matches[1]) + 127); }, $V341be97d) What you have now is quite a bit different to the point that it won't actually work correctly. If you're using PHP 7.4 or later, you can simplify the function syntax if you want by using a function shorthand: function(...) { return ... } can be shortened to fn(...) => ... preg_replace_callback("/\+([\x01-\x7F])#/", fn($matches) => chr(ord($matches[1]) + 127), $V341be97d) The second one preg_replace("/#(#|[0-9a-f]{2})/ie", "'\\1' == '#' ? '#' : chr(hexdec('\\1'))", $V341be97d) is similar preg_replace_callback("/#(#|[0-9a-f]{2})/i", function($matches) { return '\\1' == '#' ? '#' : chr(hexdec('\\1')); }, $V341be97d) but has a little more to replace, creating preg_replace_callback("/#(#|[0-9a-f]{2})/i", function($matches) { return $matches[1] == '#' ? '#' : chr(hexdec($matches[1])); }, $V341be97d) or with the PHP 7.4 shorthand, preg_replace_callback("/#(#|[0-9a-f]{2})/i", fn($matches) => $matches[1] == '#' ? '#' : chr(hexdec($matches[1])), $V341be97d) The latest one you're working on preg_replace('/\^([^\^<])/e', "'`' . \$V70dda5df[ord('\\1') % 8]", $V341be97d) goes very much the same way preg_replace_callback('/\^([^\^<])/', function($matches) { return '`' . \$V70dda5df[ord('\\1') % 8]; }, $V341be97d) preg_replace_callback('/\^([^\^<])/', function($matches) { return '`' . \$V70dda5df[ord($matches[1]) % 8]; }, $V341be97d) except it has a wrinkle: it tries to use the $V70dda5df variable. You need to adjust the syntax a bit by removing the backslash (it was needed because the code lived inside a string) but also for the fact that variables aren't accessible inside functions... unless you explicitly tell PHP you want that with a "use" attached to the function. That results in, preg_replace_callback('/\^([^\^<])/', function($matches) use ($V70dda5df) { return '`' . $V70dda5df[ord($matches[1]) % 8]; }, $V341be97d) The thing about variables doesn't apply to shorthand functions, so with PHP 7.4 you could simply write preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d)
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.