如何根据URL值在php中动态更改<title>标签

AFG*_*AFG 2 php meta-title html-title

我希望更改标题页,以便爬虫可以看到它.

该URL的格式为:public.sample.com/account/Disney

我使用require()加载标准的全局头文件包含文件

这是定义当前默认标签的位置.

如果网址是public.sample.com/account/Disney,我希望标记为:

这是迪士尼的帐户个人资料

我相信有些东西需要写在这个全局头文件中,但不确定是什么.

谢谢.

Bea*_*sen 6

让您入门的超级简单示例.

<title><?php
if ( preg_match('/([^\/]+)\/([^\/]+)$/', $_SERVER['PHP_SELF'], $matches) ) {
    list($dummy, $profileType, $profileName) = $matches;
    $safeProfileType = htmlentities($profileType);
    $safeProfileName = htmlentities ($profileName);
    echo "This is an $safeProfileType profile for $safeProfileName";
} else {
    echo "Unknown profile!";
}
?></title>
Run Code Online (Sandbox Code Playgroud)

根据Allain Lalonde的评论.(希望这是他的意思)