jverner Posted September 26, 2012 Share Posted September 26, 2012 When I run this, the hyperlink comes out in text. How do I make the hyperlink come out live? <?php> $pc = $_POST['pc']; If ($pc == 0) { $pcText = "http://www.yahoo.com"; } else if ($pc == 1) { $pcText = "http://www.google.com"; } ?> <p>Website: <?php echo $pcText ?> </p> Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/ Share on other sites More sharing options...
gizmola Posted September 26, 2012 Share Posted September 26, 2012 You are returning html, so you need to return a valid anchor tag: <a href="..."> Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/#findComment-1381204 Share on other sites More sharing options...
coded4u Posted September 26, 2012 Share Posted September 26, 2012 This should be in the PHP section, not HTML. but just edit your code a little.... <?php $pc = $_POST['pc']; If ($pc == 0) { $pcText = "<a href=\http://www.yahoo.com\">SomeText</a>"; } else if ($pc == 1) { $pcText = "<a href=\"http://www.google.com\">SomeText</a>"; } ?> <p>Website: <?php echo $pcText ?> </p> Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/#findComment-1381216 Share on other sites More sharing options...
matthewtbaker Posted October 5, 2012 Share Posted October 5, 2012 You are currently echoing the URL as text. You need to echo it as a hyperlink so the browser will know what to do. See below. <?php echo "<a href=\"" . $pcText . "\">" . $pcText . "</a>"; ?> Matt Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/#findComment-1382858 Share on other sites More sharing options...
deathadder Posted October 6, 2012 Share Posted October 6, 2012 <?php> $pc = $_POST['pc']; ]If ($pc == 0) { $pcText = "<a href=http://www.yahoo.com'>yahoo.com</a>"; } else if ($pc == 1) { $pcText = "<a href='http://www.google.com'>Google.com</a>"; } ?> there you go, i edited your php code, all you have to do is paste it Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/#findComment-1383188 Share on other sites More sharing options...
Darghon Posted October 22, 2012 Share Posted October 22, 2012 very short code, but a bit harder to read => <?php $pcText = sprintf('<a href="%1$s">%1$s</a>',$_POST['pc'] == 0 ? 'http://www.yahoo.com' : 'http://www.google.com'); ?> Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/#findComment-1386981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.