?
Solved

HTML vs PHP generated code

Posted on 2004-10-07
4
Medium Priority
?
257 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 120 total points
ID: 12253547
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 80 total points
ID: 12253549
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
ID: 12253681
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
ID: 12254274
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month15 days, 14 hours left to enroll

850 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