Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:35:03+00:00 2026-05-24T22:35:03+00:00

I am using heredoc to build a simple text email, but for some reason

  • 0

I am using heredoc to build a simple text email, but for some reason I am getting strange results around my if/else conditional:

<?php 
$message = <<<EOD
Hi Username
EOD;

echo $message.'<hr>';

if(true) {
    $message .= <<<EOD
Thanks for logging in
EOD;                    
} else {
    $message .= <<<EOD
Thanks for signing up.  
EOD;
}       

echo $message.'<hr>';   

$message .= <<<EOD
Good Bye                    
EOD;
echo '<pre>'.$message.'</pre>';

Output:

Hi UsernameThanks for logging in
EOD;                    
} else {
    Hi Username .= <<<EOD
Thanks for signing up.  Good Bye    

For some reason it’s outputting my PHP – if I change true to false I just get Hi UsernameGood Bye which is even more puzzling.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:35:04+00:00Added an answer on May 24, 2026 at 10:35 pm

    Your EOD; should be ALL that is present on the line. Only those 4 characters.

    You did fine for the first, third and fourth EOD;, but the second EOD; has whitespace behind the EOD;. Select the code (or view in hexedit or showing whitespace) to see:

    $message = <<<EOD
    Hi Username
    EOD;
    
    echo $message.'<hr>';
    
    if(true) {
        $message .= <<<EOD
    Thanks for logging in
    EOD;                    
    } else {
        $message .= <<<EOD
    Thanks for signing up.  
    EOD;
    }       
    
    echo $message.'<hr>';   
    
    $message .= <<<EOD
    Good Bye                    
    EOD;
    echo $message;
    

    Image clarification:

    http://img803.imageshack.us/img803/826/whitespaceheredoc.png

    This causes everything between the second EOD and the third EOD to be considered as the here-document 🙂

    If you would have used EOD1, EOD2, EOD3 and EOD4, you’d have gotten the warning ‘EOD2 not found’ or something along those lines.
    You’re not the first to encounter this error, the PHP HereDoc Manualpage even shows a warning (with whitespace before the heredoc endmarker). What hakre added is indeed correct, as also explained on the manpage: ‘possibly’ a semicolon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a heredoc where I am using #{} to interpolate some other strings,
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Is it possible and is it the correct way to code using heredoc inside
Note: I'm sorry if this is an extremely simple question but I'm somewhat obsessive
Using NLTK and WordNet , how do I convert simple tense verb into its
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
What is the advantage of using heredoc in PHP, and can you show an
I'm having trouble with using beestings in a heredoc in a global function. The
Using JavaScript to dynamically add and animate text in a specific group in SVG,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.