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

  • SEARCH
  • Home
  • 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 8182647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:55:18+00:00 2026-06-07T00:55:18+00:00

I’m a newbie to PHP/SQL and I am trying to use a variable within

  • 0

I’m a newbie to PHP/SQL and I am trying to use a variable within a heredoc as I need to output a lot of text. I’ve only included the first sentence as it is enough to show the problem).

My problem is that within the heredoc, the variables (see below: $data['game_name] and $data['game_owner']) are not recognized as variables, but as plain text. How can I solve this?

$response = $bdd->query('SELECT * FROM video_game');
while ($data = $response->fetch())
{

    echo <<<'EX'
    <p>Game: $data['game_name']<br/>
    the owner of the game is $data['game_owner']
    </p>
    EX;
}
  • 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-06-07T00:55:20+00:00Added an answer on June 7, 2026 at 12:55 am

    Your heredoc needs a little modification (because it’s actually Nowdoc!):

        echo <<<EX
        <p>Game: {$data['game_name']}<br/>
        the owner of the game is {$data['game_owner']}
        </p>
        EX;
    
    • Heredoc identifiers (unlike nowdoc ones) cannot be quoted. 'EX' needs to become EX.

      You’re confusing Nowdoc with heredoc.

    • Complex data types in strings must be surrounded by {} for them to be parsed as variables. For example, $data['game_name'] should be {$data['game_name']}.

    • In the obsoleted PHP versions ( before PHP 7.3) the heredoc terminator must not have any preceding whitespace. From the documentation:

      The closing identifier may be indented by space or tab, in which case the indentation will be stripped from all lines in the doc string. Prior to PHP 7.3.0, the closing identifier must begin in the first column of the line.

    You’re mixing up heredoc and nowdoc here. You want to use heredoc and not Nowdoc because you’ve got variables inside your string. Heredocs are "extended" double quoted strings, whereas nowdocs are more akin to a single quoted string, in that variables are not parsed in nowdoc strings, but are in heredoc.

    • More on heredoc here.
    • More on Nowdoc here.

    Please read the documentation more carefully on these.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has

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.