This has been closed as a duplicate of display-html-in-html and while, in principle the same applies here, there are some notable caveats.
The PHP interpreter is looking for the magic string "<?php" - that's what you need to encode in the source file to prevent PHP execution. And also any occurrence of "?>" within your snippets. You can apply the substitutions documented, or simply break the string:
print "<?" . "php";
However you still need to encode other stuff to prevent it being interpreted as a directive to the browser.
PHP provides a function for doing this: htmlentities()
This will automatically replace any of the control structures used in HTML.
But PHP goes further - specifically for rendering PHP source code, you can use the highlight_file() and highlight_string() functions. These will do the character replacements but also apply colours to the output to make it easier to visualize.
(there's also third party libraries, e.g. GeSHi, which can do this for PHP and other programming languages).
I would recommend you consider using highlight_file() to keep the PHP content you want to show separate from the code you want to execute - it can get quite confusing when you are only embedding PHP in HTML or vice-versa - as you add layers ots going to get confusing as to what is code and what is content.