有没有办法覆盖一个页面's <title>在正文中使用PHP标记


Is there a way to overwrite a page's <title> tag by using PHP within the body?

我对PHP很不熟悉,想知道是否有一种方法可以通过在正文中使用PHP来覆盖标题标签中显示的内容。

让我解释一下我为什么要这么做。我正在使用一个论坛/cms软件,允许我创建PHP页面,但不会让我改变任何关于标题(包括标题标签)。我希望有一个脚本,我可以放在正文中使用PHP,将覆盖任何显示到默认的标题标签。

这可能是一个疯狂的问题,如果是这样,我道歉。

我不知道如何在标题中得到我需要的东西。

谢谢!

你不能。

如果你想改变它,添加一些Java脚本代码,将在客户端执行,并为你做这些:

 <script>
 document.title = "This is the new page title.";
 </script>

和一些PHP:

<head><title>some title</title></head>
<body>
   <?php if (some condition, etc) { ?>
   <script>
        document.title = "This is the new page title.";
   </script>
   <?php } ?>
</body>
<html>
    <head>
        <title>Hello</title>
    </head>
    <body>
        <?
            echo "<script>document.title='Hello, World!';</script>";
        ?>
    </body>
</html>