Have you look at he source code of your (resulting) page inside your browser ?
Is it displaying something between "Entering PHP" and "Leaving PHP" ?
The PHP code actually ?
In what file (filename) do you save the whole code ?
For instance, let's say you save it in a "example.html" file. If "html" extension
is not associated with PHP engin inside Apache configuration, the PHP portion
will never be executed.
If that's the case, then try renaming your file to "example.php" and then call it.