Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>';
            
    }
            
    ?>

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •