embiding a link in a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tara83
    New Member
    • Feb 2007
    • 11

    embiding a link in a variable

    i'm working on a project where i need to embed an html link in a variable


    $link = "<a href=\"update.p hp?id='.$row['id'].\'">Update</a>";


    and i keep getting this:

    Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 88
    --------------------------------------------------------------------------------

    on the other hand i tried to test it as an echo

    echo '<a href="update.ph p?id='.$row['id'].'">Update</a>'; <<<< works

    any idea what is the right syntax


    hope some one can help
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    The difference between the echo statement and the $link statement is the type of quotes you use: in the $link version, you start off with double-quotes, but try to escape them (for the row id) with single quotes.

    Originally posted by Tara83
    i'm working on a project where i need to embed an html link in a variable

    $link = "<a href=\"update.p hp?id='.$row['id'].\'">Update</a>";

    and i keep getting this:

    Parse error: parse error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 88
    --------------------------------------------------------------------------------

    on the other hand i tried to test it as an echo

    echo '<a href="update.ph p?id='.$row['id'].'">Update</a>'; <<<< works

    any idea what is the right syntax

    hope some one can help

    Comment

    • Tara83
      New Member
      • Feb 2007
      • 11

      #3
      any idea how?

      i tried $linko = "<a href=\"update.p hp?id='.$row[\'id\'].'\">Update</a>";

      but didnt work

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        [PHP]$linko = '<a href="update.ph p?id='.$row['id'].'">Update</a>';[/PHP]but

        Comment

        Working...