Are you running a web browser (maybe apache) on localhost and connecting
to
http://localhost/filename.php to view the php page?
If not, how are you viewing it on localhost?
To see the output from the php, you need to have a web browser that knows
about php running on the server (which in this case is localhost) and
request the php page from that webserver.
The webserver then sees that the file is a .php file, calls the php
processor to process the file, takes the output from the php processor
and sends it to the requesting client as the web page.
Technically a php file referenced by url on a webserver is a resource
that generates a web page (or something else - it could deliver a file or
send dynamically generated binary content of some sort) when it is
processed by the php script processor, and not a web page (although
mostly they seem to be used to generate (x)html web pages).
I mention all of this as an incorrect use of the terminology often
indicates a lack of understanding of the processes involved, and if you
don't understand the processes involved, it's not impossible that you
haven't get things set up correctly for what you want to do.
Rgds
Denis McMahon