heredoc

Advantages / inconveniences of heredoc vs nowdoc in php

纵饮孤独 提交于 2019-11-26 19:28:02
问题 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). 回答1: Nowdocs are to single-quoted strings what heredocs are to double

HEREDOC interfering with code indentation

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 16:51:03
问题 I like the HEREDOC syntax, e.g. for edge cases of generated HTML that are not worth putting into a template. The only thing that annoys me about it, though, is that the content, and the closing marker of a heredoc string adheres to the first column. This screws up nested code layouts: class myclass { function __construct() { $a = some_code(); $b = some_more_code(); $x = <<<EOT line1 line2 line3 line4 EOT; $c = even_more_code(); $b = still_more_code(); ... ... ... you see what I mean. Now this

Javascript heredoc

纵然是瞬间 提交于 2019-11-26 15:39:13
问题 I need something like heredoc in JavaScript. Do you have any ideas for this? I need cross-browser functionality. I found this: heredoc = '\ <div>\ <ul>\ <li><a href="#zzz">zzz</a></li>\ </ul>\ </div>'; I think it will work for me. :) 回答1: Try ES6 String Template , you can do something like var hereDoc = ` This is a Multiple Line String `.trim() hereDoc == 'This\nis\na\nMultiple\nLine\nString' => true You can use this great feature today by with 6to5 or TypeScript 回答2: No, unfortunately

How to avoid heredoc expanding variables? [duplicate]

*爱你&永不变心* 提交于 2019-11-26 15:18:16
This question already has an answer here: How to cat <<EOF >> a file containing code? 3 answers I'm trying to create a script file using substitution string from ENV but want also to prevent some from escaping export PLACEHOLDER1="myPlaceholder1Value" export PLACEHOLDER2="myPlaceholder2Value" sudo /bin/su -c "cat << EOF > /etc/init.d/my-script #!/bin/bash # ### BEGIN INIT INFO # Provides: my-script # Required-Start: \$remote_fs \$syslog # Required-Stop: \$remote_fs \$syslog # Should-Start: \$network \$time # Should-Stop: \$network \$time # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short

Passing a variable to a remote host in a bash script with ssh and EOF [duplicate]

♀尐吖头ヾ 提交于 2019-11-26 14:39:30
问题 This question already has an answer here: Passing external shell script variable via ssh 2 answers I have a script parsing a list of servers, looking for some stuff and executing commands if the circumstances are correct. The main server is connecting to them via ssh, executing all commands that are in the EOF statement: #!/bin/bash # parsing servers # defining one local variable $VAR ssh -T -p 1234 root@"server-ip" "$variable" << 'EOF' # doing some stuff... var_result=$(mysql -hhost -uuser '

PHP expression <<<EOB

萝らか妹 提交于 2019-11-26 13:51:39
I've been developing with PHP for some years now, and recently came across this code: <?php echo <<<EOB <html> <head> <title>My title</title> </head> ... EOB; ?> I've never seen this approach to print HTML, which seems to be pretty useful and less prone to some weird variable or double quote syntax error. I've searched for some official information about this and only found a post of Rasmus talking about this. What is a detailed explanation about this functionality and what does EOB mean? Maybe end of block ? This is known as heredoc syntax. The documentation will tell you everything you need

How do I remove leading whitespace chars from Ruby HEREDOC?

心不动则不痛 提交于 2019-11-26 12:23:09
问题 I\'m having a problem with a Ruby heredoc i\'m trying to make. It\'s returning the leading whitespace from each line even though i\'m including the - operator, which is supposed to suppress all leading whitespace characters. my method looks like this: def distinct_count <<-EOF \\tSELECT \\t CAST(\'#{name}\' AS VARCHAR(30)) as COLUMN_NAME \\t,COUNT(DISTINCT #{name}) AS DISTINCT_COUNT \\tFROM #{table.call} EOF end and my output looks like this: => \" \\tSELECT\\n \\t CAST(\'SRC_ACCT_NUM\' AS

Calling PHP functions within HEREDOC strings

為{幸葍}努か 提交于 2019-11-26 11:43:50
In PHP, the HEREDOC string declarations are really useful for outputting a block of html. You can have it parse in variables just by prefixing them with $, but for more complicated syntax (like $var[2][3]), you have to put your expression inside {} braces. In PHP 5, it is possible to actually make function calls within {} braces inside a HEREDOC string, but you have to go through a bit of work. The function name itself has to be stored in a variable, and you have to call it like it is a dynamically-named function. For example: $fn = 'testfunction'; function testfunction() { return 'ok'; }

What does <<-CONSTANT do?

好久不见. 提交于 2019-11-26 08:38:02
问题 return <<-HTML <li> <a href = \"some-link\">Link-Title</a> </li> HTML What are <<-HTML on the first line and HTML on the last line for? 回答1: It's a heredoc. http://en.wikipedia.org/wiki/Here_document#Ruby 回答2: That's a here document. Basically, it's a multi-line string literal. On lines after the line with the <<-HTML , those are literal strings concatenated by newlines-- until the end marker is reached, which in this case is HTML . 回答3: To explicitly answer the question, this snippet returns

Using variables inside a bash heredoc

为君一笑 提交于 2019-11-26 06:39:20
I'm trying to interpolate variables inside of a bash heredoc: var=$1 sudo tee "/path/to/outfile" > /dev/null << "EOF" Some text that contains my $var EOF This isn't working as I'd expect ( $var is treated literally, not expanded). I need to use sudo tee because creating the file requires sudo. Doing something like: sudo cat > /path/to/outfile <<EOT my text... EOT Doesn't work, because >outfile opens the file in the current shell, which is not using sudo. Mark Longair In answer to your first question, there's no parameter substitution because you've put the delimiter in quotes - the bash manual