How can PHP code be displayed in a form textarea without being executed?

To display PHP code in a form textarea without executing it, you can simply escape the PHP tags by using htmlentities or htmlspecialchars functions. This will convert the PHP code into its HTML entity equivalents, preventing it from being interpreted as executable code.

<?php
$php_code = "<?php echo 'Hello, World!'; ?>";
$escaped_code = htmlentities($php_code);
?>

<textarea><?php echo $escaped_code; ?></textarea>