Questions tagged [heredoc]

A Here-document is a special syntax of writing literal strings in sourcecode, used by different programming languages.

A heredoc or Here-Document is a way of writing literal strings in sourcecode. Many languages use heredocs: PHP, Perl, C#...

Although syntax can differ between programming languages, most heredocs start by putting a keyword, and end when the keyword is encountered as the only element on a line (no spaces, tabs or other characters are allowed). Perl example:

my $text = <<KEYWORD; #Any non-reserved word would do
This is some text.
It can contain $othervariables which will be replaced
Unless KEYWORD was between single quotes, in Perl.
KEYWORD
761 questions
0
votes
1 answer

Retrieve data from SQL using PHP

First link goes to a question I've asked concerning an issue related to the use of Heredoc syntax I am unable to fix an issue concerning an HEREDOC syntax error Second link goes to a question very similar to the above link Issue with heredoc and…
Riccardo
  • 66
  • 2
  • 16
0
votes
2 answers

I am unable to fix an issue concerning an HEREDOC syntax error

This is the link in order to avoid to be marked as duplicate Issue with heredoc and PHP I haven't been able to solve the issue following the solutions provided by the developers. Within this snippet of code there must be certainly a syntax error…
Riccardo
  • 66
  • 2
  • 16
0
votes
3 answers

Have trouble when using heredoc syntax in PHP

wamp
  • 5,789
  • 17
  • 52
  • 82
0
votes
1 answer

Parsing a heredoc with Nokogiri

I have a Ruby method that uses Nokogiri to parse a heredoc. It currently looks like this and passes all specs: def html_headers Nokogiri::XML::DocumentFragment.parse(<<-HTML) .... HTML end However, when I change it to the following, it fails…
Comrade_Question
  • 305
  • 1
  • 2
  • 10
0
votes
1 answer

Combining single and double quotes in JavaScript

I'm wondering if JavaScript has a writing format for using html elements that have both single and double quotes inside JavaScript functions. May be something like heredoc for javascript or it could be a function in jQuery. I couldn't find a…
candle
  • 1,963
  • 3
  • 15
  • 24
0
votes
0 answers

PHP Heredoc with Arrays and Writing Bash Scripts

I'm trying to write a bash script from within PHP. I have an array of functions to run that I want to append to the script, along with custom code snippets and other variables. $my_array_of_bash_cmds = Array ( [0] => bash_cmd1 [1] =>…
stacked
  • 277
  • 3
  • 9
0
votes
1 answer

How can I create an array assignment from HEREDOC text using PHP?

I have a list of strings I need to convert into an array assignment eg lets say I have a set of lines like this: ctools_export_ui_list_form masquerade_block_1 switchtheme_switch_form backup_migrate_ui_manual_backup_load_profile_form …
vfclists
  • 19,193
  • 21
  • 73
  • 92
0
votes
1 answer

Create a shell script with a shell script

I'm creating a script which create file and insert content using cat > /etc/file <
Rck
  • 33
  • 5
0
votes
3 answers

How should subprocess be used for commands featuring here-documents and multiple pipes?

How could I use subprocess instead of os to run in Bash a command such as the following?: import os text = "~|||-:this is text:-|||~" fileName = "sound.wav" command =\ "IFS= read -d \'\' text <
d3pd
  • 7,935
  • 24
  • 76
  • 127
0
votes
1 answer

'End' command in shell script

I am trying to understand part of a shell script that appears to be very confusing for me. This is the snippet. My questions are: a) what does <<- do? Is it like a standard expression . I am only aware of > , >> and < for redirection. b) What could…
Santhiya
  • 99
  • 2
  • 3
  • 7
0
votes
2 answers

Android (5.0.1) Chrome is deleting javascript whitespace and comments, is there a way to stop this?

In addition to making debugging almost impossible, this new behavior is breaking my website where I use the heredoc javascript technique, (Javascript heredoc) which depends on using comments. I'm not sure if I inadvertably turned this on, and this…
MLU
  • 181
  • 1
  • 6
0
votes
2 answers

using here document and pipeline of sh at the same time

I'm using here document of sh to run some commands. now I want to parse the output of those commands using awk. However, everytime I execute it, I get the output of the command append with something like this "% No such child process" This is how…
user3714598
  • 1,733
  • 5
  • 28
  • 45
0
votes
2 answers

Use a here-document with execvp

I'm trying to run the command "wc -l << END" using execvp, so I'm parsing the command and runing execvp with "wc -l" but then it goes into an infinite loop. How can I make it work so it stops when it finds the keyword (in this case END)? I have to…
Mark
  • 71
  • 1
  • 8
0
votes
2 answers

How to escape variable name in PHP's Heredoc?

I have a variable $foo with some id in it and I want to use it in Heredoc string in PHP like this: $text = <<
TEXT; Obvious problem is that PHP parses variable in Heredoc as $foo_bar which of course, doesn't exist.…
Frodik
  • 14,986
  • 23
  • 90
  • 141
0
votes
1 answer

How to use Heredocs with XPath

I struggle with the following problem: Have an XPath like so (as you can see quite long): '//h2[contains(text(),"Kontakt")]/../following-sibling::div[contains(@class,"body") and child::dl[contains(@class,"horizontal")]]' Now, to make it more…
Severin
  • 8,508
  • 14
  • 68
  • 117