Jump to content

Archived

This topic is now archived and is closed to further replies.

PleaseHelpPlease

Hyperlink using PHP variable

Recommended Posts

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>

 

 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.