【问题标题】:How get page title dynamically in PHP如何在 PHP 中动态获取页面标题
【发布时间】:2017-06-08 19:02:00
【问题描述】:

我正在获取我的主页标题,但在获取内页(可变帖子)时它不起作用。

$path=$_SERVER['PHP_SELF'];
$page_title=basename($path);
switch($page_title){
    case 'index.php':
        $title="Welcome to the the website";
        $description="description goes here";
        break;
    case 'about.php':
        $title="Welcome to the the website";
        $description="somehtinfd";
        break;
    case 'career.php':
        $title="Welcome to the the website";
        $description="ome textr";
        break;   
    /*IT's NOT WORKING HERE*/
    case 'post.php?post_id=1':$title="graphics design services";
        $description= "about ";
        break;
}

【问题讨论】:

  • $_SERVER['PHP_SELF'] 不返回 url 的查询字符串。仅尝试使用文件名 post.php
  • 'post.php?post_id=1' — 您是否查看过要与之比较的 $page_title 的值?
  • 嘿兄弟我怎样才能得到这种类型的值
  • @manian 嘿兄弟,我怎样才能得到 url 的查询字符串

标签: php get title


【解决方案1】:

我认为你可以使用 get()。

case 'post.php':
    If($_GET["post_id"]== "1"){ 
        $title="graphics design services";
        $description= "about ";
    }elseif($_GET["post_id"]== "2"){

    }
    break;

所以用例获取页面post,使用get获取ID。

【讨论】:

    【解决方案2】:
    <title> <?php echo $title; ?> </title>
    <meta type="description" content="<?php echo $description ?."</meta>
    

    【讨论】:

    • 当你只有一个标题时它会帮助你,否则使用相同的开关。
    • 那么我怎么能得到这个值 case 'post.php?post_id=1':$title="graphics design services"; $description="关于";休息;
    猜你喜欢
    • 2011-03-21
    • 2015-01-04
    • 2019-06-13
    • 1970-01-01
    • 2010-10-12
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多