How can the e-modifier in preg_replace() be utilized to apply functions like html_entity_decode() to the replaced text?

When using the e-modifier in preg_replace(), you can apply functions like html_entity_decode() to the replaced text by using the following syntax: '/pattern/e'. This allows you to execute PHP code within the replacement string, providing flexibility in manipulating the replaced text.

$text = "Hello & World!";
$decoded_text = preg_replace('/&([^;]+);/e', 'html_entity_decode("\\1")', $text);
echo $decoded_text; // Output: Hello & World!