Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    45
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question hyperlink variable

    Hi, ok so I was trying to make a link using a variable.
    e.g.:

    $name=home
    $link=index.html

    echo "<a href='$link'>$name</a>";

    doesn't seem to be working. What am I doing wrong?

    Thanks for any help!

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,466
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    PHP Code:

    $name
    ="home";
    $link="index.html";

    echo 
    "<a href='$link'>$name</a>"

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Or

    PHP Code:
    $name="home";
    $link="index.html";

    echo 
    '<a href="'.$link.'">'.$name.'</a>'
    Basically you forgot to quote your strings, and $ for variables is taken as a literal character in single quotes. When doing double quote strings with variables in them, I prefer to put squiggly braces around the variable.

    PHP Code:
    echo "<a href=\"{$link}\">{$name}</a>"


  •  

    Posting Permissions

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