PDA

View Full Version : Need help to parse this in php


Jade Dragon
5-24-04, 04:46 PM
I'm trying to get this bit of code to parse correctly.

$menu_string .= '<div class="offnav2" onmouseover="this.className='onnav2';" onmouseout="this.className='offnav2';" ><span class="menu"><a href="';

Now I know the problem is the ; but I'm not having any luck on setting up the structure to parse it correctly.

Parse error: parse error, unexpected T_STRING

I've been looking at code way to long today, anyone want to give me a hint?

=)
Jade

B&T
5-24-04, 04:49 PM
Put in another character. Then do a string replace for that character with ;

RSaucier
5-24-04, 05:35 PM
I'm trying to get this bit of code to parse correctly.

$menu_string .= '<div class="offnav2" onmouseover="this.className='onnav2';" onmouseout="this.className='offnav2';" ><span class="menu"><a href="';

Now I know the problem is the ; but I'm not having any luck on setting up the structure to parse it correctly.

Parse error: parse error, unexpected T_STRING

I've been looking at code way to long today, anyone want to give me a hint?

=)
JadeActually, the problem is the single-quotes in the string -- PHP is getting all confused. Try this:$menu_string .= '<div class="offnav2" onmouseover="this.className=\'onnav2\';" onmouseout="this.className=\'offnav2\';" ><span class="menu"><a href="';

Jade Dragon
5-24-04, 05:41 PM
Actually, the problem is the single-quotes in the string -- PHP is getting all confused. Try this:$menu_string .= '<div class="offnav2" onmouseover="this.className=\'onnav2\';" onmouseout="this.className=\'offnav2\';" ><span class="menu"><a href="';

PERFECT!! :D

Darn quotes anyway. :rolleyes:

Thank you!
=)
Jade

Lightwar6
5-24-04, 06:02 PM
Its good to get into the habit of taking the time and encapsing the quotes with slashes. Although it takes a bit longer to code but generally saves you time with stupid parse errors.

B&T
5-24-04, 06:11 PM
Now I know the problem is the ; but I'm not having any luck on setting up the structure to parse it correctly.Silly me . . . tried to answer the question asked without actually looking at the problem. Glad you got it working.

RSaucier
5-24-04, 07:16 PM
Thank you!Glad I could help!

Pig
5-24-04, 07:23 PM
A very easy solution when you have a lot of single and double quotes (eg: javascript within PHP) is here docs.


$menu_string .=EOF
'<div class="offnav2" onmouseover="this.className='onnav2';" onmouseout="this.className='offnav2';" ><span class="menu"><a href="'
EOF;


This way you never have to escape anything.