yes you can save your file with php extension .php , but you need a server to run that file because php is a server side language ..so you can run it on "localhost".
so after adding the php code and save it with the .php just put your file to localhost server and run through it.