How can regex patterns be optimized for easier text formatting in PHP without having to use multiple preg_replace_callback functions?

To optimize regex patterns for easier text formatting in PHP without using multiple preg_replace_callback functions, you can use the preg_replace function with the /e modifier. This modifier allows you to use a callback function directly in the replacement string, making it easier to apply multiple formatting rules in a single regex pattern.

$text = "Hello, this is a sample text with some formatting tags <b>like bold</b> and <i>italic</i>.";
$formatted_text = preg_replace('/<([^>]+)>/', '"<$1>"', $text);
echo $formatted_text;