Solved

HTML vs PHP generated code

Posted on 2004-10-07
4
237 Views
Last Modified: 2010-08-05
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:
<?php
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).
0
Comment
Question by:michaelbrewitt
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 30 total points
Comment Utility
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:

<?php
echo "<span class=\"style6\" id=\"TestSpan\" onMouseOver=\"MM_changeProp('TestSpan','','innerHTML','New text','SPAN')\">Text in span</span>";
?>
0
 
LVL 33

Assisted Solution

by:snoyes_jw
snoyes_jw earned 20 total points
Comment Utility
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
onMouseOver=\"MM_changeProp...'SPAN')\">


0
 
LVL 1

Author Comment

by:michaelbrewitt
Comment Utility
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
0
 
LVL 27

Expert Comment

by:Diablo84
Comment Utility
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.

|)iablo
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now