Sublime Forum

Sublime Text 2 PHP Syntax Highlighting inside a string

#1

I’m considering moving from Notepad++ to Sublime Text 2 but as a php web developer I am find one feature to be sorely missed, the ability to have syntax highlighting for php inside a string. For example if I have a file with both php and html it is likely I will have bits of code like this:

In Notepad++ everything between the php start and end tags would be highlighted in the correct colors, in Sublime Text 2 everything appears as a string (yellow in Monokai) except the -> symbols which have the correct color applied.

Is there an adjustment somewhere that I need to make to my settings or is just a bug or the way things are?

0 Likes

PHP inline highlight
#2

You need to edit the php.tmlanguage file to include php code inside strings between <?= > code.

0 Likes

#3

thanks for the reply atomi, but how do I actually do that? Any chance you could give me the code I’d need to insert/change?

0 Likes

#4

Easiest way is to add source.php to the quoted strings.

--- D:\Dropbox\Workspace\Projects\SublimeBin\PHP.tmLanguage Fri Jan 27 06:43:10 2012
+++ D:\Dropbox\Workspace\Projects\SublimeBin\PHP-Updated.tmLanguage Thu Feb 23 17:01:46 2012
@@ -2255,6 +2255,10 @@
                    <key>include</key>
                    <string>#interpolation</string>
                </dict>
+               <dict>
+                   <key>include</key>
+                   <string>source.php</string>
+               </dict>
            </array>
        </dict>
        <key>string-single-quoted</key>
@@ -2290,6 +2294,10 @@
                    <string>\\\\']</string>
                    <key>name</key>
                    <string>constant.character.escape.php</string>
+               </dict>
+               <dict>
+                   <key>include</key>
+                   <string>source.php</string>
                </dict>
            </array>
        </dict>
0 Likes

#5

what file must be changed?

Can you explain more?

Thanks!

0 Likes

#6

FWIW, I found when using a theme from Textmate (which worked correctly with php strings) my strings were not colored in ST2.

So, I edited the .tmTheme file I was using, to add it:

<dict> <key>name</key> <string>PHP String</string> <key>scope</key> <string>meta.string-contents.quoted.double.php</string> <key>settings</key> <dict> <key>foreground</key> <string>#9E7D61</string> </dict> </dict>
And it works. Not sure if this is your issue or not.

0 Likes