How can PHP tags be resolved within a function to ensure proper execution of code for output?

To ensure proper execution of PHP code within a function, PHP tags can be resolved by using the `eval()` function. This function evaluates a string as PHP code and executes it. By passing the PHP code as a string to `eval()`, the tags will be properly resolved within the function.

function execute_php_code($php_code) {
    ob_start();
    eval("?>" . $php_code);
    $output = ob_get_clean();
    return $output;
}

// Example usage
$php_code = "<?php echo 'Hello, World!'; ?>";
echo execute_php_code($php_code);