• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

HTML vs PHP generated code

There must be a simply answer to this but it's annoying the hell out of me. Please help.

(what I am asking may seem pretty pointless but it is the root of my problem)

In my web page I have the HTML code:
<span class="style6" id="TestSpan" onMouseOver="MM_changeProp('TestSpan','','innerHTML','New text','SPAN')">Text in span</span>

I also have:
echo "<span class='style6' id='TestSpan1' onMouseOver='MM_changeProp('TestSpan1','','innerHTML','New text1','SPAN')'>Text in span1</span>";

I must lack some basic understanding... but why does the HTML work and the php doesnt???????

When I view the webpage and go to view/source the output is the same (except for double and single quote differences).
  • 2
2 Solutions
Its a quote issue, your switching between single and double quotes the wrong way when you use the php version, instead escape the double quotes in this case using backslash, eg:

echo "<span class=\"style6\" id=\"TestSpan\" onMouseOver=\"MM_changeProp('TestSpan','','innerHTML','New text','SPAN')\">Text in span</span>";
That's exactly why - the double and single quote differences.  For the HTML version, you've got
"MM_changeProp('***we're still inside double quotes***')"

The PHP version has
'MM_changeProp('***we just lost our quotes

Change the php version to

michaelbrewittAuthor Commented:
Thanks - couldn't ask for more.

I just copied Diabs code in and it worked (with minor typo tweak)

Snoyes - you helped me further understand - thanks
No problem :)

what was the typo btw? couldn't see a problem with the escaping, i copied and edited the html version or the code you posted so maybe it originated there?...

Anyway, best of luck with your code.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now