jverner Posted September 26, 2012 Share Posted September 26, 2012 (edited) 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> Edited September 26, 2012 by Pikachu2000 Removed link to competing forum. Quote 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="..."> Quote 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> Quote 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 Quote 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 (edited) <?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 Edited October 6, 2012 by deathadder Quote 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 (edited) 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'); ?> Edited October 22, 2012 by Darghon Quote Link to comment https://forums.phpfreaks.com/topic/268834-how-to-echo-hyperlinks/#findComment-1386981 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.