繁体   English   中英

我该如何更改 <title>根据网址值在php中动态标记

[英]How can I change the <title> tag dynamically in php based on the URL values

我希望更改标题页,以便爬网程序可以看到它。

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

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

这就是定义当前默认标签的地方。

如果URL是public.sample.com/account/Disney,则我想读取标签,而不是:

这是迪士尼的帐户资料

我相信需要在此全局头文件中编写一些内容,但不确定是什么。

谢谢。

超级简单的示例,助您入门。

<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>

根据Allain Lalonde评论编辑。 (希望这就是他的意思)

我不确定在这里到底要找什么,但是要获得动态标题,您可以执行以下操作:

<title><?php echo $theDynamicTitle; ?></title>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM