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

Static Function Call's Result in HEREDOC

I just tried the following: And in the browser I get: // Used by JS var delUrl = '{ScriptManager::getDelUrl()}'; Instead of seeing the result of…
Dzhuneyt
  • 8,437
  • 14
  • 64
  • 118
0
votes
1 answer

Launch webserver with no configuration file

I really like the concept of firing up an HTTP daemon to serve something like the current working directory in the file system without the distraction of configuring modules, directories, permissions etc. (instant gratification for programmers). My…
Sridhar Sarnobat
  • 25,183
  • 12
  • 93
  • 106
0
votes
2 answers

Error when outputting php and javascript from inside quotes or heredoc

I keep getting the error "Parse error: syntax error, unexpected T_SL" when attempting to use the following code : 'example1', 2 => 'example2', 3 => 'example3', 4 => 'example4'); $code =…
0
votes
1 answer

PHP Lamba-style function code throwing a slew of of undefined variable errors

I'm using PHP create_function to make a lamba-style function whose contents are defined by a heredoc style string. Everything was fine until I moved the code to a Hostgator account. Something about the Hostgator environment is causing the function…
JamesHoux
  • 2,999
  • 3
  • 32
  • 50
0
votes
2 answers

Alternative of heredoc syntax

Is there anything in HTML like heredoc syntax in PHP? Because in case of a span with long text I have to use br tags each time I want to have a linebreak.
0
votes
1 answer

Bash: Search a script for a block of commands and then execute those commands

I have a script, named bundle, which uses Here-documents to combine text files into a single file. The files, whose names are passed as arguments when calling the bundle script, are placed within a single file (here named filebundle) which can then…
primussucks
  • 293
  • 2
  • 5
0
votes
2 answers

Javascript working fine in HTML but not in PHP Heredoc

I'm a major noob to php and I might be biting off more than I can chew here. That being said, I'm facing the following problem: I've created a form using HTML that dynamically generates additional rows for responses using javascript with the click…
neanderslob
  • 2,633
  • 6
  • 40
  • 82
0
votes
2 answers

Any advantage in using php heredoc strings rather than adding slashes before quotes?

I. Are there any advantages in using heredoc format rather than using ' and "? The only obvious one, is that when we use heredoc format, we do not need the \' or \". Any other reason to use heredoc? Maybe from the aspect of processing speed and…
Mohammad Naji
  • 5,372
  • 10
  • 54
  • 79
0
votes
4 answers

PHP disable escaping in heredoc

I have PHP which gives minified JS as output through heredoc. Look at this code: function prerefresh(){$("#len").empty();predata.forEach(item)} As I have bolded above, the {$ disturbs my heredoc due to variable escaping. Is there any way to disable…
gerrnar
  • 407
  • 1
  • 6
  • 15
0
votes
1 answer

Peculiarity in saving heredoc to a variable in bash

When creating heredocs in bash using the $( construct then newlines are being changed to dollar signs $. stephenb@gondolin:/shared/git2/etl/appminer$ IRB=$(cat -e<<'HERE' > require 'irb/ext/save-history' > IRB.conf[:SAVE_HISTORY] = 100 >…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
0
votes
1 answer

Executing a set of commands inside a new bash instance from as script

I'm trying execute a set of commands in a new bash session: exec bash <<- EOF ln -snf $JDK_REPO'/jdk'$1 $CURRENT; JAVA_HOME=$(readlink -f $CURRENT); echo $JAVA_HOME; export PATH= $JAVA_HOME/bin:$PATH; exec usejdk EOF I get this…
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
0
votes
1 answer

Making an alias for SSH MySQL login using ENDSSH heredoc

I want to make an alias that is kept in my bashrc file to log into a remote MySQL db via SSH. Assume that I can't add/alter any files on the remote machine that I'm SSHing into. Here's the relevant code. function ssh_mysql { echo "SSHing to…
sojojo
  • 3
  • 5
0
votes
3 answers

HEREDOC error for text inclusion in a mail function

I am using HEREDOC to include some text into the body of a mail PHP function. However, I get this error: "PHP Parse error: syntax error, unexpected T_SL in..." The errors refers to the HEREDOC part of the included file:
samyb8
  • 2,560
  • 10
  • 40
  • 68
0
votes
1 answer

PHP While Loop - Writing to Variable Multiple Times With Heredoc

I am writing a script to pull from the database and dynamically create a table of items. The loop I am using breaks everytime I try to increment a varible. Here is an example with the same result: This loop will work fine for creating multiple…
0
votes
2 answers

why does all the text get printed on the same line?

Possible Duplicate: Have I misunderstood what heredoc should do? I read that Here document preserves the line breaks and other whitespace (including indentation) in the text. But when I run the following script,everything gets printed on the same…
saplingPro
  • 20,769
  • 53
  • 137
  • 195