If you open a HTML file using your browser, it will open fine. However, this is not the case with PHP because PHP needs to be processed on a web server. If you open a PHP file with your browser, it will show your PHP code. In order to open a PHP file using your browser, you need to download a local web server. A few examples are MAMP, XAMPP and WAMP.
Once you downloaded a web server, you will need to put your files in your working folder. Normally, it is either “public_html” or “htdocs”. However, it can be something else. Once you put your files in that folder, go to localhost/filename.php if the name of your file is filename.php. Before, you do that make sure your web server is online (don’t make the mistake I did).