Hi
I have a image gallery, in which i for each cell use a script to change the background of the cell, and it works fine as long as i keep it in html.
But i'm converting my gallery to php now, and im getting a problem with the code.
When i echo in php, i use " to enclose the echoed statements, and convert all statements within to use ' instead of ".
This makes the code to change the cell bg not to react on rollover
Example:
When i echo this in php, it dosen't have the rollover. it works fine in plain html:
Quote: echo "<td height='80' onmouseover="this.style.backgroundColor='#676c58'; " onmouseout="this.style.backgroundColor='#383b30';" align='center'><a href='#'><img src='Billeder/Thumbs/tmb05.jpg' width='70' height='70' border='0' /></a></td>" I think it's a problem with the ' and the " signs.
Do you have a solution or a work around, it would be much appreciated.
Thanks in advance.
problem with echo " and '
Started by ht56y, Sep 11 2007 09:52 AM
3 replies to this topic
#1
Posted 11 September 2007 - 09:52 AM
#2
Posted 11 September 2007 - 01:10 PM
When I use HTML inside an echo function, I do it like so...
If you use double quotes instead of single quotes, you need to add a forward slash (\) before every double quote in your HTML. Just use single quotes, it's much easier.
echo('Hello, my name is <span style="font-color: red">Chris</span>, how are you?');
If you use double quotes instead of single quotes, you need to add a forward slash (\) before every double quote in your HTML. Just use single quotes, it's much easier.
#3
Posted 11 September 2007 - 01:15 PM
That solved it, thanks
#4
Posted 11 September 2007 - 01:35 PM
For the sake of learning, the problem is here:
You need to escape the double quotes using a backslash. Of course, my prefered method is like CJ, to use single quotes around the html.
ref: http://php.net/types.string
Quote
echo "<td height='80' onmouseover="this.style.backgroundColor='#676c58'; " onmouseout="this.style.backgroundColor='#383b30';" align='center'><a href='#'><img src='Billeder/Thumbs/tmb05.jpg' width='70' height='70' border='0' /></a></td>"
ref: http://php.net/types.string
Edited by rc69, 11 September 2007 - 01:36 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
