I love Notepad++, partly because of its syntax highlighting: in a .php file, it will highlight <script> blocks as javascript, <style> blocks as css and <?php blocks as php. Ideally you'll put that javascript and css in separate files, but of course that's not the point.

Now, I know Notepad++ has SQL highlighting as well (for example by default in .sql files), but now I wonder how I can get this "inside" my php file. The issue is of course that SQL queries don't exactly have opening and closing tags, they're just strings passed to a php function. But perhaps there is something built in that can be used, something like how <editor-fold> in NetBeans will denote a collapsable block of code, but instead of that, something to denote a string as SQL. Could also be inside the SQL string itself, something like

$query = <<<END
SELECT `field` FROM `table` WHERE 1

Or better yet, by configuring at the top of the file in comments, or even in a Notepad++ setting, which functions take SQL strings as attributes (then you don't need it every time inside your code).

So anyway, there are ways, but does one of them already exist?

  • phpStorm enables syntax highlighting like this (also works for CSS, JS, HTML, ...). Apparently it's not available in Notepad++, but this seems like a really nice convention that they could add too. (Unfortunately newlines don't work in comments like here, so use your imagination) $query = <<<SQL SELECT `field` FROM `table` WHERE 1 SQL; – Sygmoral Jul 4 '15 at 16:02

Not NP++, but SynWrite editor: it can use one lexer inside other. Eg, in PHP lexer open "Lexer properties" dialog and on Sublexers tab add rule for SQL. It can be string with SQL with some marks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.