Home > programming > Multi-Line Strings and Text Editors

Multi-Line Strings and Text Editors

March 30Hits:2
Advertisement

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 = "
SELECT
product.productid,
product.title
FROM
product
WHERE
product.type='boardgame'
";

This next example uses heredoc syntax, which allows you to specify a token to end the string with.


$sql = SELECT
product.productid,
product.title
FROM
product
WHERE
product.type='boardgame'
ENDOFSTRING;

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:


$sql =
"SELECT"
. " product.productid,"
. " product.title"
. "FROM"
. " product"
. "WHERE"
. " 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.

Tags:

Related Articles

  • Multi-Line Strings and Text EditorsMarch 30

    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

  • How Can I Set XCode to Correctly Highlight Multi-Line Strings for Shell Scripts?October 14

    Quite simply I have a shell script that I'm editing in XCode, and it contains several strings which contain new-lines. Easiest way for me to do this was just to leave the string open so that it spans several lines in the file, and as far as I know th

  • How to make Webstorm keep indent of multi line string literals during reformatFebruary 6

    When creating a directive for angularjs I often keep my templates as string literals. Sometimes the templates span several lines, so I indent them the way I would indent a html file for better readability. Here is a very simple example template: '<di

  • How to translate multi-line strings?March 15

    If there is a long string in PHP like this: <?php $text = "Some ... very very... long string"; Can it be localized by GetText wrapping it in __(), e.g. <?php $text = __("Some ... very very... long string", "domain"); ?

  • How to manipulate a multi-line string in luatex?

    How to manipulate a multi-line string in luatex?June 15

    I want to write a Lua function that processes some multi-line string. Thus, I created a new file test.lua which contains userdata = userdata or {} function userdata.surroundwithdashes(str) str = str:gsub("\n", " (linebreak)\\\\ ") tex.

  • Preserving Pre-formatted Multi-Line Strings in Node.js ScriptsFebruary 25

    There is a lot I don't like about PHP, but one thing I love is multi-line strings: $query = <<<EOT select field1 ,field2 ,field3 from tableName where field1 = 123 EOT; What's cool about this, is that I can just copy SQL, that I've hand formatted

  • I have a multi-line string that I need to iterate over, but I'm not using bash. Advice?April 22

    I'm using Dash because this is to run on my rPi. Bash is not an option. I'm rewriting a Bash script to work with Dash. I'm hoping to make it as POSIX-compliant (portable) as possible. The thing is it's difficult to find help on how to do loops throug

  • How to use Powershell to filter out multi-lines group of text from a file?January 14

    I have an error log that I would like to filter out all the known errors using Powershell. I know how to filter by line in powershell, but my problem is that the errors in the error log span multiple lines, but they always start with a date time. Eg:

  • How to embed multi-line block of text in mathsOctober 18

    What is the best way to embed a multi-line block of text, surrounded by curly braces, in maths mode? The best I can do is the following hack. \[ {\text{bounded WD-representations} \brace \text{of $W_K$ over $\overline{\mathbf{Q}}_l$}} \] ------------

  • Can I pass a multi-line string to svn in PowerShell?August 24

    I have the following line in a script: svn propset svn:externals $newExternals $path Now for the first time $newExternals is a multi-line string (there are several svn:external properties) and svn barks at me in a way that seems to indicate that it c

  • Line numbers in text editorJanuary 16

    Okay this sounds like a question a six year old would ask, (and I hope there is an empirical answer) so here's my inner child: In programming numbers start from from zero but why do line numbers in text editors (for programming) also start from one?

  • Parsing multi-line string to extract only matched linesFebruary 5

    I have a multi-line string and I'd like to only extract lines that match a certain pattern and discard the rest of the string. Original string: lorem ipsum dolor sit amet consectetur nunc KEEP THIS LINE ut massa lorem DO NOT KEEP THIS LINE aenean bla

  • Search directories for multi line stringFebruary 4

    Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines.

  • Golang idiomatic way to remove a blank line from a multi-line stringFebruary 12

    If I have a multi line string like this is a line this is another line what is the best way to remove the empty line? I could make it work by splitting, iterating, and doing a condition check, but is there a better way? --------------Solutions-------

  • How can I use sed to replace a multi-line string?December 7

    I've noticed that, if I add \n to a pattern for substituting using sed, it does not match. Example: $ cat > alpha.txt This is a test Please do not be alarmed $ sed -i'.original' 's/a test\nPlease do not/not a test\nBe/' alpha.txt $ diff alpha.txt{,.o

  • How to copy and paste $n$ lines from a text editor to $n$ cells?

    How to copy and paste $n$ lines from a text editor to $n$ cells?June 21

    If I copy from an external editor to Mathematica notebook a block of lines (with a code) line 1 line 2 ... line n then whole text is copied to a single cell. I can now use n-1 times "Divide cell" and manually create n new cells for each line. If

  • How to insert javascript HTML code into Multi line Sharepoint 2007 text field

    How to insert javascript HTML code into Multi line Sharepoint 2007 text fieldNovember 3

    I have a Javascript variable that contain HTML code as follows: <DIV>Hello World<BR>Welcome to SharePoint Stack Exchange</DIV> So, how do I insert it into the SharePoint 2007 Multi line text field (The meaning of a SharePoint 2007 Multi

  • Why are line numbers in text editors and programming IDEs so often disabled by default?July 6

    It feels like most environments for editing code have line numbers hidden by default. For example, Eclipse, IntelliJ, Oracle SQL Developer, and Vim all seem to have the default setting as not showing line numbers, and so developers must go into the s

  • How do I do multi-line editing in Atom editor?August 14

    I've been reading all over and I can't find anything on how to do this in Atom on Windows? And by multi-line editing, I mean being able to expand your cursor across multiple-lines, and being able to type, and that whatever you have typed replicates o

  • Linux - Bash - Copying multi-line strings from source to terminalDecember 13

    I am writing notes as I prepare a system so I have something to follow if/when I need to prepare another system. Also I am hoping to use these notes and implement into a puppet configuration at some point. I am trying to write multi-line bash command

Copyright (C) 2018 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 1.128 s.