Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-24-2012, 10:47 PM   PM User | #1
colbyaley
New to the CF scene

 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
colbyaley is an unknown quantity at this point
Links aren't working under 'echo'

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?

PHP Code:
<?
$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>';
        
}
        
?>
colbyaley is offline   Reply With Quote
Old 07-24-2012, 11:13 PM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
PHP Code:
echo ""<a href="http://minipress.me/login">Login</a> -"; 
huhwat?

You are echoing incorrectly.

PHP Code:
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.
Keleth is offline   Reply With Quote
Reply

Bookmarks

Tags
echo, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:17 AM.


Advertisement
Log in to turn off these ads.