SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parse error: expecting 'T_VARIABLE' or '$'

    What the heck does that mean?

    Here's the code I'm having trouble with:

    echo "var $mi" . "a = new Image(); $mi" . "a.src=\"menubtn.php?str=" . $str[0] . "\";\nvar $mi" . "b = new Image(); $mi" . "b.src=\"menubtn.php?str=" . $str[0] . "&tx=blue\";\n\n";

    Tried everything I could think of (which is admittedly not much). What's going wrong?

  2. #2
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, Ill do you a favor and clean it up, then I will explain what I did...

    PHP Code:
    echo "var $mi a = new Image(); $mi a.src='menubtn.php?str=" $str[0] . "';\nvar $mi b = new Image(); $mi b.src='menubtn.php?str=" $str[0] . "&tx=blue';\n\n"
    Okay...
    (1) The PHP parcer looks for $inside the "'s and replaces it with the value of that variable. In other word... if you are trying to represent a price, you need to use "\$" or else it will think you are trying to display a variable.
    (2)When working with an array, you will have to concat it since the parser gets a little confuxxelec with the extra "'s
    (3) In most languages ' and " are interchangable. BUT, which ever one inside is passed over as a value and not a string identifier. It makes long concatinations look better with less \'s...

    Hope I helped.
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  3. #3
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What did you change? Besides the \" to ' that is.

    You messed it up in one place. Where you have "$mi a" it HAS to be "$mi" . "a" because there's a variable with the name of (the value of) "$mi" . "a" in the Javascript which the PHP is generating. I couldn't have it as "$mia" because then it would think I meant a variable named $mia... does that make sense?

    Thanks for your help by the way.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is faithful to what you want:
    PHP Code:
    echo 'var '$mi'a = new Image(); '$mi'a.src="menubtn.php?str='$str[0], '";'"\n",
         
    'var '$mi'b = new Image(); '$mi'b.src="menubtn.php?str='$str[0], '&tx=blue";'"\n\n"
    Note, I use a comma "," to seperate the bits of string (treating them as arguements) rather that a period "." which concatenates the bits into one large string. Each to their own, both ways work.

  5. #5
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still getting the exact same parse error... <sigh>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •