1

我想在我的代码、设置关键字、描述和页面标题方面得到一些帮助。

我的 head.php(包含在 index.php 中):

<?php 
$current = $SERVER_[REQUEST_URI];
$home = "/#!/page_HOME";
if($current==$home) {
  $title = "Example.com || Home";
  $keywords = "some words";
  $description = "description text";
}   
?>

我的网站使用“奇怪”的 URL,例如:http://example.com/index.php#!/page_HOME. Is 是一个使用 CSS 和 jQuery 技巧来加载不同页面的网页。

现在我想通过单击菜单链接来更改页面的关键字、描述和标题。

在 index.php 中,菜单和包含语句如下所示:

**link in menu:** 
<a href="#!/page_HOME">Home</a>
**include in webpage:** 
<li id="page_HOME">
    <a href="#!/page_SPLASH" class="close"></a>  
    <?php include('home.html'); ?>
</li>

我试过用$SERVER_[REQUEST_URI]等等来做这件事,但我做不到。

请帮助解决这个“问题”

4

1 回答 1

0

parse_url()您可以使用;检索锚片段(# 之后的所有内容)见: http: //php.net/parse_url

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$urlFragment = parse_url( $url, PHP_URL_FRAGMENT );

switch( $urlFragment )
{
    case '!/page_SPLASH':
        $title = "Example.com || Splash";
        $keywords = "splash content";
        $description = "splash description text";
        break;

    /* define more pages here */

    case '!/page_HOME': /* no break; intended */
    default:
        $title = "Example.com || Home";
        $keywords = "some words";
        $description = "description text";
        break;
}
于 2013-09-13T14:05:06.547 回答