heredoc

What is the advantage of using Heredoc in PHP? [closed]

我们两清 提交于 2019-11-26 00:15:24
问题 What is the advantage of using Heredoc in PHP, and can you show an example? 回答1: The here doc syntax is much cleaner to me and it is really useful for multi-line strings and avoiding quoting issues. Back in the day I used to use them to construct SQL queries: $sql = <<<SQL select * from $tablename where id in [$order_ids_list] and product_name = "widgets" SQL; To me this has a lower probability of introducing a syntax error than using quotes: $sql = " select * from $tablename where id in [

How does “cat << EOF” work in bash?

馋奶兔 提交于 2019-11-25 23:47:37
问题 I needed to write a script to enter multi-line input to a program ( psql ). After a bit of googling, I found the following syntax works: cat << EOF | psql ---params BEGIN; `pg_dump ----something` update table .... statement ...; END; EOF This correctly constructs the multi-line string (from BEGIN; to END; , inclusive) and pipes it as an input to psql . But I have no idea how/why it works, can some one please explain? I\'m referring mainly to cat << EOF , I know > outputs to a file, >> appends

here-document gives &#39;unexpected end of file&#39; error

心已入冬 提交于 2019-11-25 23:10:07
问题 I need my script to send an email from terminal. Based on what I\'ve seen here and many other places online, I formatted it like this: /var/mail -s \"$SUBJECT\" \"$EMAIL\" << EOF Here\'s a line of my message! And here\'s another line! Last line of the message here! EOF However, when I run this I get this warning: myfile.sh: line x: warning: here-document at line y delimited by end-of-file (wanted \'EOF\') myfile.sh: line x+1: syntax error: unexpected end of file ...where line x is the last

Creating multiline strings in JavaScript

旧时模样 提交于 2019-11-25 22:12:53
问题 I have the following code in Ruby. I want to convert this code into JavaScript. what\'s the equivalent code in JS? text = <<\"HERE\" This Is A Multiline String HERE 回答1: Update: ECMAScript 6 (ES6) introduces a new type of literal, namely template literals. They have many features, variable interpolation among others, but most importantly for this question, they can be multiline. A template literal is delimited by backticks : var html = ` <div> <span>Some HTML here</span> </div> `; (Note: I'm

heredoc for Windows batch?

为君一笑 提交于 2019-11-25 22:07:16
Is there a way of specifying multiline strings in batch in a way similar to heredoc in unix shells. Something similar to: cat <<EOF > out.txt bla bla .. EOF The idea is to create a customized file from a template file.. Not as far as I know. The closest I know of is > out.txt ( @echo.bla @echo.bla ... ) ( @ prevents the command shell itself from printing the commands it's running, and echo. allows you to start a line with a space.) rojo Here's another approach. @echo off :: ###################################################### :: ## Heredoc syntax: ## :: ## call :heredoc uniqueIDX [>outfile]