Quotes not appearing after variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Josh

    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("Q L","Quick Links) onmouseover = display_desc("Q uick
    Links) ><font color =" red">X</font></a>&nbsp;<br />
    <a style =" cursor: pointer" onmouseout =" clear_desc()" onclick =
    delete_block("A D","Admin Menu) onmouseover = display_desc("A dmin Menu)[color=blue]
    ><font color =" red">X</font></a>&nbsp;<br />[/color]

    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.
  • Josh

    #2
    Re: Quotes not appearing after variables

    Someone must have some ideas, come on now, please?

    Comment

    • Josh

      #3
      Re: Quotes not appearing after variables

      Well I finally got it today. I tried and still try the single quotes
      and it fails saying "Unterminat ed 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

      Comment

      • Josh

        #4
        Re: Quotes not appearing after variables

        Well I finally got it today. I tried and still try the single quotes
        and it fails saying "Unterminat ed 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

        Comment

        • Michael Fesser

          #5
          Re: Quotes not appearing after variables

          .oO(Josh)
          [color=blue]
          >Well I finally got it today. I tried and still try the single quotes
          >and it fails saying "Unterminat ed String Literal".[/color]

          What PHP version? Can you strip it down to a short line of code (as
          short as possible) that still shows the error?
          [color=blue]
          >I have no idea why adding those single quotes made any effect on it
          >displaying the double quotes,[/color]

          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.
          [color=blue]
          >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<s p?> it messes everything all up.[/color]

          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\")'[color=blue]
          ><font color = 'red'>X</font></a>&nbsp;\n";[/color]

          Micha

          Comment

          Working...