laurajohn89 Posted April 14, 2010 Share Posted April 14, 2010 Hi. I am echoing event information into a table and one of my variables I am echoing is a website. I was wondering how I could make it echo like a hyperlink. The code I currenrlt have is: echo "<tr><td>Website: " . $row['website'] . "</td></tr>"; I was wondering where the a href would come into this? Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/ Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Hi. I am echoing event information into a table and one of my variables I am echoing is a website. I was wondering how I could make it echo like a hyperlink. The code I currenrlt have is: echo "<tr><td>Website: " . $row['website'] . "</td></tr>"; I was wondering where the a href would come into this? echo "<tr><td>Website: <a href='" . $row['website'] . "' /></td></tr>"; Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041729 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Assuming $row['website'] is the URL ... echo "<tr><td>Website: <a href='" . $row['website'] . "'>LINK</a></td></tr>"; Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041731 Share on other sites More sharing options...
DWilliams Posted April 14, 2010 Share Posted April 14, 2010 Or for a way that's easier to read (IMO anyway): echo "<tr><td>Website: <a href='{$row['website']}'>link text</a></td></tr>"; String concatenation is ugly! Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041734 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 And variable interpolation isn't ugly? :-\ echo sprintf("<tr><td>Website: <a href='%s'>link text</a></td></tr>", $row['website']); Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041738 Share on other sites More sharing options...
aeroswat Posted April 14, 2010 Share Posted April 14, 2010 Or for a way that's easier to read (IMO anyway): echo "<tr><td>Website: <a href='{$row['website']}'>link text</a></td></tr>"; String concatenation is ugly! imo concatenating my variables to my string is the easiest to read/decipher for others Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041746 Share on other sites More sharing options...
laurajohn89 Posted April 14, 2010 Author Share Posted April 14, 2010 Thank you. I want the link text to then be the . $row['website'] . variable. This: echo "<tr><td>Website:<a href='" . $row['website'] . "' . $row['website'] . /></td></tr>"; Doesn't work. Thank you once again. Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041783 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 You missed an opening quote. Here's a better way - echo sprintf('<tr><td>Website: <a href="%1$s">%1$s</a></td></tr>', $row['website']); Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041784 Share on other sites More sharing options...
laurajohn89 Posted April 14, 2010 Author Share Posted April 14, 2010 That works. However when I click on the link now it takes me to mysite.com/thelinksite not thelinksite.com. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041814 Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 So $row['website'] is just the domain name? You should really be more specific. echo sprintf('<tr><td>Website: <a href="http://%1$s/">%1$s</a></td></tr>', $row['website']); Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041816 Share on other sites More sharing options...
laurajohn89 Posted April 14, 2010 Author Share Posted April 14, 2010 thank you. Sorry I'm an undergrad Link to comment https://forums.phpfreaks.com/topic/198528-echoing-a-hyperlink/#findComment-1041820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.