dongmen1925 2015-04-09 09:01
浏览 8
已采纳

PHP - 如何将*(任何内容)连接到当前URL

I got a problem. I use curPageUrl() function to locate the link to my file and use it as 'active' to get some CSS effects.

This is the curPageUrl() code:

function curPageURL() {
    $pageURL = 'http';
    if ($_SERVER['HTTPS'] == "on") {
        $pageURL .= "s";
    }
    $pageURL .= "://";
    if ($_SERVER['SERVER_PORT'] != "80") {
        $pageURL .= $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
    } else {
        $pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    }
    return $pageURL;
}

And this is my html code:

<a href='home.php'><li class="<?php if (curPageUrl() == 'http://something/home.php') {echo 'active';} ?>">Home</li></a>

But the problem begins when I start using $_GET[] method so the next link http://something/home.php?some_get_code is no more 'active'.

How can I concatenate everything after home.php so my link still be active?

  • 写回答

2条回答 默认 最新

  • dongquan6030 2015-04-09 09:06
    关注

    Use this:

    <a href='home.php'>
        <li class="<?php if (strpos(curPageUrl(),'http://something/home.php') !== false) {echo 'active';} ?>">Home</li>
    </a>
    

    Use strpos function of PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?