...

View Full Version : hyperlink variable



whatg
06-22-2010, 02:56 PM
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!

mlseim
06-22-2010, 03:08 PM
$name="home";
$link="index.html";

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

Keleth
06-22-2010, 03:59 PM
Or


$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.


echo "<a href=\"{$link}\">{$name}</a>";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum