Home Download Buy Blog Forum Support

Sublime Text 2 PHP Syntax Highlighting inside a string

Sublime Text 2 PHP Syntax Highlighting inside a string

Postby chilliFreak on Wed Feb 22, 2012 10:52 pm

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:
<input type="hidden" name="calendar_id" id="calendar_id" value="<?=$this->calendar->id?>" />

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?
chilliFreak
 
Posts: 2
Joined: Wed Feb 22, 2012 10:42 pm

Re: Sublime Text 2 PHP Syntax Highlighting inside a string

Postby atomi on Wed Feb 22, 2012 11:42 pm

You need to edit the php.tmlanguage file to include php code inside strings between <?= > code.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Sublime Text 2 PHP Syntax Highlighting inside a string

Postby chilliFreak on Fri Feb 24, 2012 12:45 am

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?
chilliFreak
 
Posts: 2
Joined: Wed Feb 22, 2012 10:42 pm

Re: Sublime Text 2 PHP Syntax Highlighting inside a string

Postby atomi on Fri Feb 24, 2012 1:05 am

chilliFreak wrote: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?


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

Code: Select all
--- 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>

atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Sublime Text 2 PHP Syntax Highlighting inside a string

Postby getmuller on Tue Mar 06, 2012 3:08 pm

atomi wrote:
chilliFreak wrote: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?


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



what file must be changed?

Can you explain more?

Thanks!
getmuller
 
Posts: 2
Joined: Tue Mar 06, 2012 3:06 pm

Re: Sublime Text 2 PHP Syntax Highlighting inside a string

Postby handycam on Tue Mar 06, 2012 4:59 pm

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:

Code: Select all
<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.
Mac OS 10.9.3
ST 3 (3059)
handycam
 
Posts: 271
Joined: Tue Jan 03, 2012 2:42 pm


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 37 guests