And exactly here is the problem
PHP had to be requested through the Webserver to get parsed by the php parser.
localhost is the alias for your own computer. And Apache knows, that requests goes directly to the htdocs folder.
So, if you have a file C:\xampp\htdocs\subfolder\test.php, the correct url is http://localhost/subfolder/test.php
You can't open your files directly in the Browser. That can't work with php