Jump to content


Photo

Hyperlink using PHP variable


  • Please log in to reply
2 replies to this topic

#1 PleaseHelpPlease

PleaseHelpPlease
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 May 2005 - 08:40 AM

We have a value in our DB called website, it is in the form www.whatever.com, we want to display as the value in DB but also be a link to that site. this is the code we have, any suggestions?

$web = $info['Website'];

<a href="$web"></a>




#2 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 23 May 2005 - 12:46 PM

One thing that I noticed:
<a href="$web"></a>
should be:
echo("<a href=\"$web\">$web</a>");

I don't know if you just left the echo out or what, but that line should work...

with $web being www.example.com: output is
<a href="www.example.com">www.example.com</a>

neylitalo
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#3 Pilot-Doofy

Pilot-Doofy
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationMustywindows.com!

Posted 29 May 2005 - 06:01 PM

echo("<a href=\"$web\">$web</a>");

The parentheses aren't need and why use escape characters when they're not needed? I wouldn't suggest hiding variables inside of double quotes, at least not when you're using Dreamweaver because Dreamweaver won't highlight variables inside of quotes.

I just don't believe it's a good habit to get into.

echo '<a href="' . $web . '">' . $web . '</a>';

If you know that your contents are going to involve only one style of quotes it's much simpler just to prevent escape characters and march on with the contradicting style for opening and closing the statement.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users