heredoc

Simple/Direct/Heredoc way of constructing a HTML string in Java

泄露秘密 提交于 2019-11-28 23:04:39
In python I can construct a HTML string without worrying about escaping special characters like < or " by simply enclosing the string in triple quotes like: html_string = """ <html> <body> <p>My text with "quotes" and whatnot!<p> </body> </html> """ Is there a similar way to do this in Java? It can't be done in Java like in Python. However if you are using Eclipse go to Window->Preferences->Java->Editor->Typing The last check box is "Escape text when pasting into a String literal". Check that. Now when you paste when your cursor is between quotation marks it'll be escaped. No, but some tools

Multiline syntax for piping a heredoc; is this portable?

纵饮孤独 提交于 2019-11-28 15:50:29
I'm familiar with this syntax: cmd1 << EOF | cmd2 text EOF but just discovered that bash allows me to write: cmd1 << EOF | text EOF cmd2 (the heredoc is used as input to cmd1, and the output of cmd1 is piped to cmd2). This seems like a very odd syntax. Is it portable? Yes, the POSIX standard allows this. According to the 2008 version: The here-document shall be treated as a single word that begins after the next <newline> and continues until there is a line containing only the delimiter and a <newline> , with no <blank> characters in between. Then the next here-document starts, if there is one

\\n in variable in heredoc

狂风中的少年 提交于 2019-11-28 11:19:47
Is there any way to for a Bash heredoc to interpret '\n\' in a heredoc? I have an iteratively built string in a loop, something like for i in word1 word2 word3 do TMP_VAR=$i ret="$ret\n$TMP_VAR" done and then I want to use the created string in a heredoc: cat <<EOF > myfile HEADER == $ret == TRAILER EOF however I would like to interpret the "\n" character as newline, so that the output is HEADER == word1 word2 word3 == TRAILER instead of HEADER == \nword1\nword2\nword3 == TRAILER Is it possible? Or should I perhaps build my initial string somehow otherwise? In bash you can use $'\n' to add a

Redirect output of command with heredoc

蹲街弑〆低调 提交于 2019-11-28 09:05:31
问题 I have a command like this: sftp user@host <<EOF put file.txt exit EOF Now I'd like to pipe the output of that to zenity --progress , but I can't find a place to put it. # SFTP doesn't work anymore sftp user@host | zenity --progress <<EOF put file.txt exit EOF # Invalid syntax, no end of heredoc sftp user@host <<EOF put file.txt exit EOF | zenity --progress # Not picked as part of the command sftp user@host <<EOF put file.txt exit EOF | zenity --progress # Does not help sftp user@host |

JavaScript HERE-doc or other large-quoting mechanism?

烂漫一生 提交于 2019-11-28 07:27:35
Is there a convenient way to quote a large block of HTML that has both single and double quotes in JavaScript? Is there anything like a HERE-doc <<EOF , a multi-quote character """ , or custom delimiters q{} ? Any creative or inventive solutions to this problem? Some people don't like this, so be prepared for scorn and derision, but one trick is to dump your "big block of stuff" into a <script language="text"> block: <script id='blockOfStuff' language="text"> Hi this is random stuff <h1>Including HTML markup</h1> And quotes too, or as one man said, "These are quotes, but 'these' are quotes too

define and heredoc

核能气质少年 提交于 2019-11-28 03:33:29
问题 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; 回答1: taken from the documentation regarding strings DEFINE('PREFIX','/holiday'); $const = PREFIX; echo <<<EOD <img src="{$const}/images/hello.png" /> EOD; 回答2: 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');

How to suppress variable substitution in bash heredocs

﹥>﹥吖頭↗ 提交于 2019-11-28 01:58:26
Is it possible to create a heredoc that does not become subject to variable expansion? e.g. cat <<-EOF > somefile.sh Do not print current value of $1 instead evaluate it later. EOF Update I am aware of escaping by \ . My actual heredoc has many variables in it - and it is error prone and tedious to escape all of them. Quote the delimiter: cat <<-"EOF" > somefile.sh Do not print current value of $1 instead evaluate it later. EOF This results in: $ cat somefile.sh Do not print current value of $1 instead evaluate it later. Documentation The format of here-documents is: <<[-]word here-document

Use variable within heredoc in PHP (SQL practice)

穿精又带淫゛_ 提交于 2019-11-27 20:03:03
I'm a newbie to PHP/SQL and I am trying to use a variable within a heredoc as I need to ut a lot of text. I've only included the first sentence as it is enough to show the problem). My problem is that within the heredoc, the variables (see below: $data['game_name] and $data['game_owner'] ) are not recognized as a variable but as plain text. How can I solve this? <?php try { //i am connecting the the database base mysql 'test' $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options); //the i read the data in the

Advantages / inconveniences of heredoc vs nowdoc in php

别说谁变了你拦得住时间么 提交于 2019-11-27 18:29:13
As a newbie, I have been advised to preferably use heredoc compared to too many nested codes (see Unexpected T_ELSE in php code ). But I can't manage to understand if there is a significant difference between heredoc and nowdoc. What would be the advantages for heredoc and nowdoc compared to the other one that would be important for a newbie to understand (i.e. not very minor advantages but important to understand for me). deceze Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc.

Dirt-simple PHP templates… can this work without `eval`?

a 夏天 提交于 2019-11-27 12:27:55
Update- Thanks for all the responses. This Q is getting kind of messy, so I started a sequel if anyone's interested. I was throwing together a quick script for a friend and stumbled across a really simple way of doing templating in PHP. Basically, the idea is to parse the html document as a heredoc string, so variables inside of it will be expanded by PHP. A passthrough function allows for expression evaluation and function and static method calls within the string: function passthrough($s){return $s;} $_="passthrough"; The code to parse the document inside a heredoc string is ridiculously