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 6728799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:12:47+00:00 2026-05-26T10:12:47+00:00

The variable $a below does not seem to parse properly when if I attempt

  • 0

The variable $a below does not seem to parse properly when if I attempt to declare it using a heredoc. It however, does work when I define it with the simple = declaration method. I would like to be able to define it as a heredoc, because a lot of HTML code must be called all at once, and in this example I have just simplified it for demonstrative purposes.


$a = "<a href = \'http://www.google.com\'>Google</a>";

echo "
  <div id = \"test\" 
      ondblclick = \"document.getElementById('test').innerHTML = '$a';\">
        Change Event
  </div>
"; 

// when the user clicks the text "Change Event", 
// it should turn into whatever $a is, in this case a link to Google

The previous code works, however when I try to convert it to a heredoc, something does not parse correctly.


I have tried using four kinds of quote styles, “, \”, ‘, and \’

\’ is the quote style required by where the variable lies in the code, within JavaScript, as the other three styles have already been used, and it is the quote that works (obviously) when I am declaring a variable in a simple (=) way.

When I use ” or \” the code yields:

Screenshot

When I use ‘ or \’ the code yields:

Screenshot2

In both cases, the ondblclick functionality does not work either. I am not sure what is going wrong and why heredoc is not parsing the way it seems like it should.


Here is one of my attempt at making the heredoc; the only difference between my attempts are the quote styles around the link.

$a = <<<EOT

    <a href = \'http://www.google.com\'>Google</a>

EOT;

// as stated above, I have tried ", \", ', and \'
  • 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-26T10:12:48+00:00Added an answer on May 26, 2026 at 10:12 am

    Hmmm trying to think of a way around this whilst still using heredoc… the double quotes within .innerHTML must be escaped when printed to the browser, or you get the problem you have. Some browsers will be kind and automatically escape them but on the whole they won’t and, if truth be told, they shouldn’t.

    The only way I can get this code to work is by removing the “” from the href attribute completely.

    It’s really not recommended to have .innerHTML used this way as the <a> tag now contains technically invlalid HTML, but it seems to work in Firefox,IE 9 (quirks mode on and off) and Chrome.

    $a = <<<EOT
    <a href=http://www.google.com>Google</a>
    EOT;
    $b = <<<EOT
    <div id="test" ondblclick="document.getElementById('test').innerHTML = '$a';">Change Event</div>
    EOT;
    echo $b;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm confused about how PHP variable references work. In the examples below, I want
why does this code not work for referencing a const from a class? Background:
The window pops up below the variable, and obscures the code I want to
In the below program: class Main { static string staticVariable = Static Variable; string
The picture below explains all: alt text http://img133.imageshack.us/img133/4206/accentar9.png The variable textInput comes from File.ReadAllText(path);
When I try to set the z variable in the code below, I get
When I try to use the code below I get a duplicate variable error
It's possible to declare variables with the below structure in C++ private: public: protected:
So I am trying to autoload classes in PHP; however, the __autoload() function does
Static variable gotcha in php I am from Java background and have switched to

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.