Quotes not appearing after variables

This is a discussion on Quotes not appearing after variables within the PHP Language forums, part of the PHP Programming Forums category; I have this block of code.... while($i <= $count) { $final = mysql_fetch_row($result); $blocknamelist .= "<a style = \"cursor: ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-16-2004
Josh
 
Posts: n/a
Default Quotes not appearing after variables

I have this block of code....

while($i <= $count)
{
$final = mysql_fetch_row($result);
$blocknamelist .= "<a style = \"cursor: pointer\" onmouseout =
\"clear_desc()\" ";
$blocknamelist .= "onclick = delete_block(\"$final[1]\",\"$final[2]\")
onmouseover = display_desc(\"$final[2]\") >";
$blocknamelist .= "<font color = \"red\">X</font></a>&nbsp;<br />\n";
$i++;
}

This is the output:

<a style =" cursor: pointer" onmouseout =" clear_desc()" onclick =
delete_block("QL","Quick Links) onmouseover = display_desc("Quick
Links) ><font color =" red">X</font></a>&nbsp;<br />
<a style =" cursor: pointer" onmouseout =" clear_desc()" onclick =
delete_block("AD","Admin Menu) onmouseover = display_desc("Admin Menu)
><font color =" red">X</font></a>&nbsp;<br />


As you can see, around Quick Links the quote sequence never shows up
as well as around Admin Menu. I can't figure this out. I have tried
these sequences:

'text "' . $variable . '" more text';
"text \"". $variable . "\" more text";
<<<EOD Text "$variable" more text EOD;

Among as many other patterns I could think of.

What I don't understand is. If I do this:

$test = '"' . $variable . '"';
it works exactly how I want it to act, as well as the same with every
above pattern I have tried. it is only when I try and get it to print
in the above manner within the javascript function calls that I get a
problem. Do the parenthesis in the string effect it some how? I've
never seen it do this before, so I am bamboozled. Any and all help is
appreciated.
Reply With Quote
  #2 (permalink)  
Old 08-18-2004
Josh
 
Posts: n/a
Default Re: Quotes not appearing after variables

Someone must have some ideas, come on now, please?
Reply With Quote
  #3 (permalink)  
Old 08-18-2004
Josh
 
Posts: n/a
Default Re: Quotes not appearing after variables

Well I finally got it today. I tried and still try the single quotes
and it fails saying "Unterminated String Literal". Anyways what I
ended up having to do is just add a single quote around the entire
javascript function call. I am really baffled as to why that code
worked for you though :-\. Anyways here is my revised code.

$blocknamelist .= "<a style = 'cursor: pointer;' onmouseout =
'clear_desc()' ";
$blocknamelist .= "onclick =
'delete_block(\"$final[1]\",\"$final[2]\")' onmouseover =
'display_desc(\"Delete $final[2] Block\")' >";
$blocknamelist .= "<font color = 'red'>X</font></a>&nbsp;\n";

I have no idea why adding those single quotes made any effect on it
displaying the double quotes, it still makes no sense to me and I
would be really intrigued to see an explanation of this. Especially
when a variable can hold the information fine, but as soon as I try to
concantenate<sp?> it messes everything all up. Very strange behavior
indeed. But thank you for your responses.

Josh
Reply With Quote
  #4 (permalink)  
Old 08-18-2004
Josh
 
Posts: n/a
Default Re: Quotes not appearing after variables

Well I finally got it today. I tried and still try the single quotes
and it fails saying "Unterminated String Literal". Anyways what I
ended up having to do is just add a single quote around the entire
javascript function call. I am really baffled as to why that code
worked for you though :-\. Anyways here is my revised code.

$blocknamelist .= "<a style = 'cursor: pointer;' onmouseout =
'clear_desc()' ";
$blocknamelist .= "onclick =
'delete_block(\"$final[1]\",\"$final[2]\")' onmouseover =
'display_desc(\"Delete $final[2] Block\")' >";
$blocknamelist .= "<font color = 'red'>X</font></a>&nbsp;\n";

I have no idea why adding those single quotes made any effect on it
displaying the double quotes, it still makes no sense to me and I
would be really intrigued to see an explanation of this. Especially
when a variable can hold the information fine, but as soon as I try to
concantenate<sp?> it messes everything all up. Very strange behavior
indeed. But thank you for your responses.

Josh
Reply With Quote
  #5 (permalink)  
Old 08-19-2004
Michael Fesser
 
Posts: n/a
Default Re: Quotes not appearing after variables

.oO(Josh)

>Well I finally got it today. I tried and still try the single quotes
>and it fails saying "Unterminated String Literal".


What PHP version? Can you strip it down to a short line of code (as
short as possible) that still shows the error?

>I have no idea why adding those single quotes made any effect on it
>displaying the double quotes,


Quotes are necessary because onXXX are attributes in HTML, their values
should be single- or double-quoted. But I have no idea how or why this
affects PHP.

>it still makes no sense to me and I
>would be really intrigued to see an explanation of this. Especially
>when a variable can hold the information fine, but as soon as I try to
>concantenate<sp?> it messes everything all up.


concatenate

Your (old) code works on my system (PHP 5.0.0 and 4.3.3). And so does
the following:

$blocknamelist = "<a style = 'cursor: pointer;'
onmouseout = 'clear_desc()'
onclick = 'delete_block(\"$final[1]\",\"$final[2]\")'
onmouseover = 'display_desc(\"Delete $final[2] Block\")'
><font color = 'red'>X</font></a>&nbsp;\n";


Micha
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:13 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0