...

View Full Version : unterminated string literal



Wurlitzer
02-11-2007, 05:52 PM
Hi all,
I'm having trouble getting rid of this error ("unterminated string literal" in Firefox and "unterminated string constant" in IE).
Here is the code responsible for the error:

$temp .= '<span id="'.$dir.'/" title="open" class="dir" onclick=\'browse(this.title, this.id);document.getElementById("'.$test.'/Info").innerHTML = "";\' />'.$dir.'</span>';
The error occurs when the php variable $test has single quotes in it.
I tried to use addslashes($test) but the error is still there.
Can anyone help me out with this?
Thanks.

chump2877
02-11-2007, 06:20 PM
Give that a shot:


$temp .= "<span id='$dir/' title='open' class='dir' onclick='browse(this.title, this.id);document.getElementById(\"$test/Info\").innerHTML = \"\";' />$dir</span>";

Wurlitzer
02-11-2007, 07:59 PM
Thanks for the reply.
I see you tried to use double quotes instead. This solution seemed perfect, however I wasn't showing completely what my code was, in order to make it simple. Here is what it looks like:


$temp .= '<span id="'.$dir.'/" title="open" class="dir" onclick=\'browse(this.title, this.id);document.getElementById("'.$test.'/Info").innerHTML = "";\' />'.$this->hyphens($dir).'</span>';

Well in fact I only changed $this->hyphens($dir).

So I applied your solution, but it shows this error now: "Undefined property: myclass::$hyphens"

I have no clue what's wrong.

chump2877
02-11-2007, 08:26 PM
that's a weird error...Do you have a property and a method both named "hyphens"? Is the error for that exact line of code?

and I'm just guessing here:


$temp .= '<span id="'.$dir.'/" title="open" class="dir" onclick="browse(this.title, this.id);document.getElementById(\''.$test.'/Info\').innerHTML = \'\';" />'.$this->hyphens($dir).'</span>';

Wurlitzer
02-12-2007, 02:33 AM
You guessed right! I don't get it, I was sure I already tried your suggestion, but it's often confusing with all these quotes and escapes I guess.
Cheers!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum