3

When I set syntax to PHP in Sublime, all thing is good in my PHP code:

code with syntax highlighted

But when I remove <?php tag from my code, the syntax highlighter doesn't work anymore:

code without syntax highlighted

How can I tell sublime to do syntax highlighting on this specific file (my file extension is .code)?

2
  • I second the problem. even I have the same issue.
    – vishal
    Commented Jul 24, 2013 at 16:51
  • I was unable to solve this. I wanted to do it because I was including PHP code using gulp-preprocess, and needed the tags to be excluded. The only solution I found was to add a step in my gulp build process to strip the tags from the file before processing step. Kind of silly, but not having the highlighting was driving me crazy.
    – dgo
    Commented Mar 24, 2015 at 3:29

2 Answers 2

2

Put #<?php at the top of the file. PHP will treat it as a comment. Sublime won't. Perfect.

1
  • I tried this, but it is far from ideal in my situation. I was importing a lot of scripts into PHP with a pre-processer, and while, able to prevent the execution of this code, it left a whole bunch of superfluous #<?php tags floating throughout the built PHP source file.
    – dgo
    Commented Mar 24, 2015 at 3:27
0

With your file open, from the View menu, choose Syntax.... Choose one of the options to set the syntax for that file only. Or, choose Open All with Current Extension As... to specify that all .code files should use the PHP syntax.

1
  • I did it before and the Syntax is set to PHP. The problem is because my file doesn't contains <?php tag, the Sublime Text won't highlight my code. Commented Jun 28, 2013 at 7:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .