How can preg_replace_callback be used as an alternative to the /e modifier in PHP?

The /e modifier in PHP is deprecated and should not be used due to security risks. To achieve similar functionality, you can use preg_replace_callback function with a callback function that evaluates the replacement string. This allows you to dynamically generate the replacement string without executing PHP code directly.

// Example of using preg_replace_callback as an alternative to the /e modifier
$string = "Hello, {name}!";
$replaced = preg_replace_callback('/\{([^\}]+)\}/', function($matches) {
    return strtoupper($matches[1]);
}, $string);

echo $replaced; // Output: Hello, NAME!