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
-2
votes
1 answer

If statement don't works in sh file

Good day. I want to automatize certain process with linux and bash. And I stuck in a IF statement. This is the code: #!/bin/bash result=$( sqlplus -s /nolog << EOF CONNECT admin/password@server; whenever sqlerror exit sql.sqlcode; set echo off …
EnzoV
  • 5
  • 4
-2
votes
1 answer

Perl here doc: how to add HTML

I'm quite new in Perl. I'm using here document to print out something in our UI. I could not find a way to add HTML code in here document. my $str = <<"EOF";

Something

EOF Please help. Thanks
Steve S.
  • 71
  • 6
-2
votes
2 answers

Escaping $ in HEREDOC string with PHP

I have something like this $var = <<
prgrm
  • 3,734
  • 14
  • 40
  • 80
-2
votes
1 answer

Using recursive functions and Heredoc together

I would like to echo a large bunch of text without having to painfully escape all the characters, will be a nightmare for debugging, and would like to use heredoc. I have read the documents and am unable to fix this. function MySwal($items, $k){ …
Rajan
  • 27
  • 1
  • 1
  • 4
-2
votes
1 answer

Heredoc php syntax error

Syntax error screenshot I am getting this syntax error while using heredoc in php. Unexpected: << after: = Can somebody help me with this?
-2
votes
2 answers

What's the error in the following PHP code?

I'm testing the following code. I'm using PHP heredoc but I'm getting an error from dreamweaver. If I write it manually, it works. If I copy paste it doesn't work. Why is that?
user5402
  • 291
  • 5
  • 16
-2
votes
2 answers

How to pass a $_POST variable inside a heredoc

I'm creating some code that will generate a new page with a configuration class. I used heredoc like below. So I want to pass $_POST['hostname'] variables into the heredoc. I tried a lot of things, but no luck. How can I do it?
dilini
  • 49
  • 2
  • 7
-2
votes
2 answers

PHP: echo heredoc from another script

I am having trouble echoing out heredoc statements from one php file into another. I have one script which is used to retrieve API database information and then format that information into a heredoc to echo the information into the index.php page.…
Human
  • 545
  • 2
  • 7
  • 22
-3
votes
1 answer

here document with HTML not identifying delimiter

What is supposed to happen when there is HTML in a here document? Isn't it supposed to just be stored as a string? The HTML in this screen is displayed on screen and so is the delimiter "HTMLBLOCK;" portion of the code. What is going on?
Bendzukic
  • 35
  • 5
-3
votes
2 answers

PHP eval not executing properly

Could someone point out what I'm mistaking here? :)
seanlevan
  • 1,367
  • 3
  • 15
  • 33
-3
votes
2 answers

How can I write PHP syntax in a string

I tried to write some content in order to write in a php file and in my $content variable i use Heredoc and nowdoc but php tags seems not working and are still shown. $content = <<< EOT
Tom
  • 3
  • 2
1 2 3
50
51