PHP conveniently allows two main methods of using multi-line strings, where a string constant is broken over many lines. However, it can be hard to find a syntax highlighting text editor that will correctly highlight multi-line strings in PHP.
When I was switched text editors recently, support for multi-line strings when syntax highlighting was high on my list of required features.
I find multi-line strings convenient for writing SQL, as writing a non-trivial SQL query on one line does not make for very readable code.
Here are two examples of multi-line strings in PHP. The first is simple a quoted string split over multiple lines.
$sql = "
This next example uses heredoc syntax, which allows you to specify a token to end the string with.
$sql = <<
The text editor I now use is Syn, which supports multi-line quoted strings but not heredoc syntax. Given the choice, I would rather use quoted strings than heredoc.
Here are all of the editors I evaluated.
Syn can highlight multi-line strings, but I found a couple of bugs in the latest version on their site, which is dated February 2004. Incidentally, if you email the developer, he'll be happy to give you a later build where the bugs are fixed. Alas, the fixes haven't made it into an official build.
I was very impressed with Notepad++ for its speed and responsiveness as well as for additional features such as code folding. Notepad++ does highlight multi-line strings correctly, but I couldn't find a way of showing a 'folder view' panel similar to that found in editors such as Syn, HTML-Kit, JEdit and Editplus. If anybody knows a way, please let me know.
TextPad does multi-line strings. What turned me off from this editor was that I couldn't find a folder view panel, and I couldn't specify bold or italic when setting up my syntax highlighting. The lack of bold and italic support is not as important to me.
JEdit does support multi-line strings in its syntax highlighting. It is a very impressive editor with a large range of plug-ins, but unfortunately I found it very slow to load. Responsiveness was one of my main criteria, and one of the reasons I chose the light-weight Syn for now.
UltraEdit looks great, but unfortunately does not have syntax highlighting for multi-line strings. According to their website, this will be supported in version 11.
Crimson editor is nice, but doesn't have support for multi-line strings. I don't know if this will be added in a future version.
HTML-Kit is a fantastic editor and used to be my editor of choice until relatively recently. While it supports heredoc syntax, it does not have support for regular multi-line strings in quotes. According to their FAQ, support will not be added and isn't available in a plugin due to architecture limitations. However, I'd definitely recommend this editor if you are not concerned with multi-line strings.
EditPlus has no support for multi-line strings, or for bold/italic when configuring syntax highlighting. Otherwise, it is very nice and has a folder view, and lots of nice extra features.
Why the need to support multi-line strings? It is just a personal preference of mine. There are alternative ways to achieve the same effect, however. For one, there is heredoc syntax, which is (to my surprise) supported by more editors that regular multi-line strings, though still not the majority. Other alternatives are workarounds such as the following:
. " product.productid,"
. " product.title"
. " product"
. " product.type='boardgame'";
I found adding those dots and quotes to be highly frustrating, however, even just now! It would make that SQL hard to maintain in future.
How do you deal with multi-line strings in your code? Do you write SQL on one line, break it into multiple strings, or use multi-line strings?
Note: Initially when I compiled this list, I wrote that JEdit does not support multi-line strings. Upon testing it today, I see that it does. I've corrected my mistake.