Scott Paterson
Scott Paterson

Reputation: 151

Display PHP without it being rendered

In a PHP page, how can I write PHP documentation without it being rendered?

Example of what I am trying to do:

<?php _e( 'Error msg, please manually add <?php echo "whatever"; ?> to this
file, 'my-text-domain' ); ?>

Upvotes: 2

Views: 62

Answers (1)

Barmar
Barmar

Reputation: 782693

Replace < and > characters with &lt; and &gt; entities to display them literally, just like you would in ordinary HTML:

<?php _e( 'Error msg, please manually add &lt;?php echo "whatever"; ?&gt; to this file, 'my-text-domain' ); ?>

You could also call the htmlentities() function to do it automatically:

<?php _e( htmlentities('Error msg, please manually add <?php echo "whatever"; ?> to this file, 'my-text-domain') ); ?>

Upvotes: 7

Related Questions