...

View Full Version : Links aren't working under 'echo'



colbyaley
07-24-2012, 11:47 PM
I am trying to echo a few links but none of them seem to be working correctly. I have a nav menu and am trying to make it so that the current page doesn't show as a link. Is this the right way to do it?


<?
$login = "/login";
$currentpage = $_SERVER['REQUEST_URI'];
if($login==$currentpage) {
echo "Login";
}
else {
echo ""<a href="http://minipress.me/login">Login</a> -";
}
?>

<?
$register = "/register";
$currentpage = $_SERVER['REQUEST_URI'];
if($register==$currentpage) {
echo "Sign Up";
}
else {
echo "<a href="http://minipress.me/register">Sign Up</a> -";
}
?>
- <?
$learn = "/learn";
$currentpage = $_SERVER['REQUEST_URI'];
if($learn==$currentpage) {
echo "Learn More";
}
else {
echo '<a href="http://minipress.me/learn">Learn More</a>';
}
?>

Keleth
07-25-2012, 12:13 AM
echo ""<a href="http://minipress.me/login">Login</a> -";

huhwat?

You are echoing incorrectly.


echo "<a href=\"http://minipress.me/login\">Login</a> -";

You first have a two double quotes in a row... PHP assumes you're starting and stopping a string with nothing inside, then you're for some reason throwing a < after it, which PHP just doesn't understand at all. So we drop a double quote in the beginning.

You then have another double quote, which again PHP just knows to close the string, does, and then you have more characters, and PHP just doesn't know what to do with. So we escape the second and third quotes.

Repeat this process for all your strings. Remember that if the string is encapsulated by double quotes, you have to escape all double quotes within. If you're using single quotes, escape single quotes.

You may want to do some research on quoting/echoing.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum