heredoc

What is <<<_END?

末鹿安然 提交于 2019-11-30 18:07:05
I'm new to PHP and don't understand what the point of <<<_END is. Could someone please explain when this should be used? I've looked at various examples and they all seem to have HTML embedded within them. But I can use HTML without the <<<_END tags, so why should I use them? I tried searching the manual, but I keep finding the end() method for arrays. It's the start of a heredoc . you can do: $data = <<< _END You can write anything you want in between the start and end _END; _END can be just about anything. You could put EOF or STUFF . as long as you use the same thing at the start and the

Is there heredoc alternative in Java (heredoc as PHP)? [duplicate]

一笑奈何 提交于 2019-11-30 17:28:33
This question already has an answer here: Java multiline string 39 answers For JAVA development I need writing to a files with strings like "\r\t\n <>", because from Java I want writing a PHP file. If you can't understand look at this example: BufferedWriter buffW = new BufferedWriter(fileW); buffW.write("<?php\n\n\tclass MyClass {\n\tpublic function test()\n}\n}\n?>"); This is mess a code, I want to write a clean such as PHP can do, but can't find on Java alternative way as example: <?php $mystring = <<<EOT This is some PHP text. It is completely free I can use "double quotes" and 'single

Heredoc in a Makefile?

女生的网名这么多〃 提交于 2019-11-30 13:13:42
问题 Is this possible at all and how? Update: I need this because I create a file both from dynamic and static data. Use case: I have a test directory. Each C file produces a test executable. With SRCS = $(wildcard [a-z]*.c) I can add new tests as needed and make will find the new tests, compile, run and valgrind them. I also use git. I would like .gitignore to include the executables. So there. How to create .gitignore and include static data, i.e. the files I want to be ignored ( *.o and depend

Why do these Heredoc and Nowdoc cause errors?

坚强是说给别人听的谎言 提交于 2019-11-30 10:21:40
I've already found some solutions, but can't know what happened... Example 1: <?php echo <<< EOD test EOD; Example 2: <?php echo <<< 'EOD' test EOD; Output 1,2: PHP Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) Example 3: <?php echo <<< EOD test EOD; ?> Example 4: <?php echo <<< 'EOD' test EOD; ?> Example 5: <?php echo <<< EOD test EOD; 'dummy'; Example 6: <?php echo <<< 'EOD' test EOD; 'dummy'; Output 3,4,5,6: test You probably have spaces after the terminator in your

Working with large text snippets in Java source

巧了我就是萌 提交于 2019-11-30 07:54:34
问题 Are there any good ways to work with blocks of text (Strings) within Java source code? Many other languages have heredoc syntax available to them, but Java does not. This makes it pretty inconvenient to work with things like tag libraries which output a lot of static markup, and unit tests where you need to assert comparisons against blocks of XML. How do other people work around this? Is it even possible? Or do I just have to put up with it? 回答1: While you could use certain formatters to

Heredoc in a Makefile?

ε祈祈猫儿з 提交于 2019-11-30 06:37:33
Is this possible at all and how? Update: I need this because I create a file both from dynamic and static data. Use case: I have a test directory. Each C file produces a test executable. With SRCS = $(wildcard [a-z]*.c) I can add new tests as needed and make will find the new tests, compile, run and valgrind them. I also use git. I would like .gitignore to include the executables. So there. How to create .gitignore and include static data, i.e. the files I want to be ignored ( *.o and depend ) and also the executables dynamically? Another GNU Make solution. You can do it using the define and

What are <— Ruby Strings called? And how do I insert variables in them?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 06:01:34
问题 <-- Seems to be unsearchable on the web so had to ask the question here. What is their searchable name, and how do I add variables inline? 回答1: That syntax is for declaring a HERE DOCUMENT http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#here_doc There's a line-oriented form of the string literals that is usually called as `here document'. Following a << you can specify a string or an identifier to terminate the string literal, and all lines following the current line

define and heredoc

丶灬走出姿态 提交于 2019-11-29 10:12:41
How do you use define within a heredoc ? For example: define('PREFIX', '/holiday'); $body = <<<EOD <img src="PREFIX/images/hello.png" /> // This doesn't work. EOD; taken from the documentation regarding strings DEFINE('PREFIX','/holiday'); $const = PREFIX; echo <<<EOD <img src="{$const}/images/hello.png" /> EOD; if you have more than 1 constant, variable usage would be difficult. so try this method define('PREFIX', '/holiday'); define('SUFFIX', '/work'); define('BLABLA', '/lorem'); define('ETC', '/ipsum'); $cname = 'constant'; // if you want to use a function in heredoc, you must save function

Working with large text snippets in Java source

不打扰是莪最后的温柔 提交于 2019-11-29 05:32:28
Are there any good ways to work with blocks of text (Strings) within Java source code? Many other languages have heredoc syntax available to them, but Java does not. This makes it pretty inconvenient to work with things like tag libraries which output a lot of static markup, and unit tests where you need to assert comparisons against blocks of XML. How do other people work around this? Is it even possible? Or do I just have to put up with it? While you could use certain formatters to convert and embed any text file or long literal as a Java string (e.g., with newline breaks, the necessary

Interpolate constant (not variable) into heredoc?

♀尐吖头ヾ 提交于 2019-11-29 01:28:06
问题 <?php define('my_const', 100); echo <<<MYECHO <p>The value of my_const is {my_const}.</p> MYECHO; ?> If i put a variable inside the braces it prints out. But not the constant. How can I do it? Thank's! 回答1: Use sprintf() define('my_const', 100); $string = <<< heredoc <p>The value of my_const is %s.</p> heredoc; $string = sprintf($string, my_const); 回答2: I'm aware that this has been answered already, but you can also approach the problem by assigning the value of the constant to a variable.