bobl61 Posted June 15, 2022 Share Posted June 15, 2022 (edited) I'm using a game stats processor for my site called VSP. I've corrected all the /e modifier errors using the preg_replace_callback function except for this one. I'm hoping someone can help. The code is: $V341be97d = preg_replace('/\^([^\^<])/e', "'`' . \$V70dda5df[ord('\\1') % 8]", $V341be97d); I'm attaching the entire php file for reference. Edited June 15, 2022 by requinix removing copyrighted file Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/ Share on other sites More sharing options...
requinix Posted June 15, 2022 Share Posted June 15, 2022 No offense but I've removed the file from your post. It doesn't look like something that's meant to be shared, but it also doesn't need to be to address this particular problem. I don't suppose there's a more up to date version of this script available, right? Because that would be ideal. If not, what did you try? The second argument is essentially PHP code, so you just need to translate that string into normal code and use it with preg_replace_callback... Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597297 Share on other sites More sharing options...
bobl61 Posted June 15, 2022 Author Share Posted June 15, 2022 (edited) 25 minutes ago, requinix said: I don't suppose there's a more up to date version of this script available, right? Because that would be ideal. If not, what did you try? The second argument is essentially PHP code, so you just need to translate that string into normal code and use it with preg_replace_callback... It's the latest working version of the script. There's supposedly a newer version, but I downloaded it and the files are corrupt. I'm not a coder, but I was able to replace other instances of the /e modifier using research. I replaced: //change: special chars if ($this->V93da65a9['xp_version'] <= 103) { // 1.03 special chars $V341be97d = preg_replace("/\+([\x01-\x7F])#/e", "chr(ord('\\1') + 127)", $V341be97d); } else { // 1.04 special chars $V341be97d = preg_replace("/#(#|[0-9a-f]{2})/ie", "'\\1' == '#' ? '#' : chr(hexdec('\\1'))", $V341be97d); } to this: //change: special chars if ($this->V93da65a9['xp_version'] <= 103) { // 1.03 special chars $V341be97d = preg_replace_callback("/\+([\x01-\x7F])#/", function($matches){ foreach($matches as $match){ return chr($match); } }, $V341be97d ); } else { // 1.04 special chars $V341be97d = preg_replace_callback("/#(#|[0-9a-f]{2})/", function($matches){ foreach($matches as $match){ return chr($match); } }, $V341be97d ); Those changes work without errors. I just can't seem to get the code in my first post to work correctly. Here's a link to the program I'm using. Edited June 15, 2022 by bobl61 Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597298 Share on other sites More sharing options...
requinix Posted June 15, 2022 Share Posted June 15, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597299 Share on other sites More sharing options...
bobl61 Posted June 15, 2022 Author Share Posted June 15, 2022 I've implemented your fixes and the program runs without errors. Only problem now is all the players have ^ characters in their names. Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597304 Share on other sites More sharing options...
bobl61 Posted June 15, 2022 Author Share Posted June 15, 2022 Here's what the code looks like now... //$V70dda5df = array("black", "red", "lime", "yellow", "blue", "aqua", "fuchsia", "white", "orange"); //change: special chars if ($this->V93da65a9['xp_version'] <= 103) { // 1.03 special chars preg_replace_callback("/\+([\x01-\x7F])#/", fn($matches) => chr(ord($matches[1]) + 127), $V341be97d); } else { // 1.04 special chars preg_replace_callback("/#(#|[0-9a-f]{2})/i", fn($matches) => $matches[1] == '#' ? '#' : chr(hexdec($matches[1])), $V341be97d); } //endchange $V70dda5df = array("#555555", "#e90000", "#00dd24", "#f5d800", "#2e61c8", "#16b4a5", "#f408f1", "#efefef", "#ebbc1b"); $tmp = array("\xde" => "^"); $V341be97d = strtr($V341be97d, array_diff_assoc($this->V42dfa3a4['char_trans'], $tmp)); if ($V341be97d[0] != "^") $V341be97d = "^7" . $V341be97d; $V341be97d = preg_replace('/\^(a[1-9]|[fFrRbBl])/', "", $V341be97d); $V341be97d = preg_replace('/\^s(\^x[a-fA-F0-9]{6}|\^[^\^])/', "\\1", $V341be97d); $V341be97d = preg_replace('/\^s/', "^7", $V341be97d); $V341be97d = preg_replace('/(\^(x[a-fA-F0-9]{6}|[^\^]))\^(x[a-fA-F0-9]{6}|[^\^])/', "\\1", $V341be97d); $V341be97d = preg_replace('/\^x([a-fA-F0-9]{6})/i', "`#\\1", $V341be97d); preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d); $V341be97d = strtr($V341be97d, $tmp); return $V341be97d; } function Fa3f5d48d($V341be97d) // parece eliminar efectos del nombre Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597308 Share on other sites More sharing options...
bobl61 Posted June 15, 2022 Author Share Posted June 15, 2022 1 minute ago, bobl61 said: parece eliminar efectos del nombre seems to remove name effects Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597309 Share on other sites More sharing options...
requinix Posted June 15, 2022 Share Posted June 15, 2022 $V341be97d = preg_replace('/\^x([a-fA-F0-9]{6})/i', "`#\\1", $V341be97d); preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d); On that second line you lost the assignment that was on the left of the function. So preg_replace_callback is running but the result isn't going anywhere. (what I posted was meant as only the bit about the function, not to be the whole line) Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597334 Share on other sites More sharing options...
bobl61 Posted June 15, 2022 Author Share Posted June 15, 2022 2 hours ago, requinix said: $V341be97d = preg_replace('/\^x([a-fA-F0-9]{6})/i', "`#\\1", $V341be97d); preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d); On that second line you lost the assignment that was on the left of the function. So preg_replace_callback is running but the result isn't going anywhere. (what I posted was meant as only the bit about the function, not to be the whole line) Uhhh... you lost me. I'm not sure what you mean. Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597342 Share on other sites More sharing options...
requinix Posted June 15, 2022 Share Posted June 15, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597345 Share on other sites More sharing options...
bobl61 Posted June 16, 2022 Author Share Posted June 16, 2022 1 hour ago, requinix said: 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. Okay, got it. Definitely getting closer. Players with special characters in their names are still not displaying properly, though. Here's what I ahve now... //$V70dda5df = array("black", "red", "lime", "yellow", "blue", "aqua", "fuchsia", "white", "orange"); //change: special chars if ($this->V93da65a9['xp_version'] <= 103) { // 1.03 special chars $V341be97d = preg_replace_callback("/\+([\x01-\x7F])#/", fn($matches) => chr(ord($matches[1]) + 127), $V341be97d); } else { // 1.04 special chars $V341be97d = preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d); } //endchange $V70dda5df = array("#555555", "#e90000", "#00dd24", "#f5d800", "#2e61c8", "#16b4a5", "#f408f1", "#efefef", "#ebbc1b"); $tmp = array("\xde" => "^"); $V341be97d = strtr($V341be97d, array_diff_assoc($this->V42dfa3a4['char_trans'], $tmp)); if ($V341be97d[0] != "^") $V341be97d = "^7" . $V341be97d; $V341be97d = preg_replace('/\^(a[1-9]|[fFrRbBl])/', "", $V341be97d); $V341be97d = preg_replace('/\^s(\^x[a-fA-F0-9]{6}|\^[^\^])/', "\\1", $V341be97d); $V341be97d = preg_replace('/\^s/', "^7", $V341be97d); $V341be97d = preg_replace('/(\^(x[a-fA-F0-9]{6}|[^\^]))\^(x[a-fA-F0-9]{6}|[^\^])/', "\\1", $V341be97d); $V341be97d = preg_replace('/\^x([a-fA-F0-9]{6})/i', "`#\\1", $V341be97d); $V341be97d = preg_replace_callback('/\^([^\^<])/', fn($matches) => '`' . $V70dda5df[ord($matches[1]) % 8], $V341be97d); $V341be97d = strtr($V341be97d, $tmp); return $V341be97d; } function Fa3f5d48d($V341be97d) // parece eliminar efectos del nombre BTW - I really appreciate all your help. Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597347 Share on other sites More sharing options...
requinix Posted June 16, 2022 Share Posted June 16, 2022 I don't see what would be responsible. Did you alter any other files? Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597348 Share on other sites More sharing options...
bobl61 Posted June 16, 2022 Author Share Posted June 16, 2022 8 hours ago, requinix said: I don't see what would be responsible. Did you alter any other files? Only the theme. Changed some images and banners. Nothing to do with the processing of the stats. I did see this further down the file. I forgot that I changed this also... //change: special chars if ($this->V93da65a9['xp_version'] <= 103) { // 1.03 special chars $Vaa8af3eb = preg_replace("/\+([\x01-\x7F])#/e", "chr(ord('\\1') + 127)", $Vaa8af3eb); } else { // 1.04 special chars $Vaa8af3eb = preg_replace("/#(#|[0-9a-f]{2})/ie", "'\\1' == '#' ? '#' : chr(hexdec('\\1'))", $Vaa8af3eb); } $Vaa8af3eb = strtr($Vaa8af3eb, $this->V42dfa3a4['char_trans']); //endchange $this->Vae2aeb93->F8405e6ea($this->Va2bbabfe[$V2bfe9d72]['id'], $this->F7212cda9($Vaa8af3eb)); } return true; } return false; } function Fe7c49e90(&$V6438c669) // si descongela (oO, no sabía esto) { To this... //change: special chars if ($this->V93da65a9['xp_version'] <= 103) { // 1.03 special chars $Vaa8af3eb = preg_replace_callback("/\+([\x01-\x7F])#/", function($matches){ foreach($matches as $match){ return chr($match); } }, $Vaa8af3eb ); } else { // 1.04 special chars $Vaa8af3eb = preg_replace_callback("/#(#|[0-9a-f]{2})/", function($matches){ foreach($matches as $match){ return chr($match); } }, $Vaa8af3eb ); Maybe that's causing it? Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597351 Share on other sites More sharing options...
requinix Posted June 18, 2022 Share Posted June 18, 2022 Isn't that what you first tried? It's not correct. Look at my second reply. Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597416 Share on other sites More sharing options...
bobl61 Posted June 18, 2022 Author Share Posted June 18, 2022 WOO-HOO! Everything is working perfectly now. The player names are perfect. The country flags are working properly. Thanks so much for your help requinix! Quote Link to comment https://forums.phpfreaks.com/topic/314927-warning-preg_replace_callback-the-e-modifier-is-no-longer-supported-use-preg_replace_callback-instead/#findComment-1597428 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.