How to Associate .php Files with Sublime Text Editor in Windows 10

When trying to associate .php extension files with Sublime Text in Windows 10, I found that the process wasn't as simple as expected. After some research and trial, I found a solution. Here's how you can do it:

STEP 1: Get the File Type Association

First, you need to get the associated name of your file type. Open Command Prompt (be sure to run it as Administrator) and run the following command:

assoc .php

This should output something like:

.php=phpfile

The phpfile is the file type you need for the next step.

STEP 2: Set the Default Program

Once you have the file type association that you would like to change, run the ftype command as follows:

ftype phpfile="C:\Dropbox\ST3\sublime_text.exe" "%1"

This command will set Sublime Text as the default program for opening files associated with the phpfile type.

Now, when you use the normal Windows methods to set the default application, Sublime Text should appear without the need to browse for it manually.

Full description about the assoc command can be found here

Notes:

If you get a response like "File association not found for extension," it means the association for that extension hasn't been created yet. To create an association, use the following command:

assoc .(xxx)=(filetype)

For example, to associate .cls extension with the javaclass file type:

assoc .cls=javaclass

After creating the association, verify it using the command from Step 1. Then proceed with Step 2 to set your preferred program.