Solved

HTML vs PHP generated code

Posted on 2004-10-07
4
240 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
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 20 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

813 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

10 Experts available now in Live!

Get 1:1 Help Now