Show php code in echo
Akam's solution sorts PHP if the Content-Type of the returned file is HTML.
Alternatively, you can change the Content-Type to Text, thereby bypassing the rendering of HTML.
<?php header( 'Content-type: text/plain' ); echo '<?php ?>'; ?> Of course, this would affect the entire page, and not just its segment. Thus, it would be useful for you to display the contents of the PHP script file as a separate page, but if you would like to display fragments of PHP code on an HTML page, then Akam's solution would be better suited for this.
If you print and pretend to see it as HTML, the browser will interpret the tag and not show anything, but you can still see it if you look at the source code. To show <and> tags properly you should use & lt; and? or use htmlentities () or the htmlspecialchars () functions :
<?php echo htmlentities( '<?php ?>' ); ?> There is another solution built on str_replace that accepts arrays for finding and replacing parameters.
<?php echo str_replace(array('<','>'),array('<','>'),'<?php ?>'); ?> Check out the following demo: http://phpfiddle.org/main/code/3hp-itx