简体   繁体   English

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

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

I want the title page to be changed so that a crawler can see it. 我希望更改标题页,以便爬网程序可以看到它。

The URL is of the format: public.sample.com/account/Disney URL的格式为:public.sample.com/account/Disney

I load a standard, global header include file using require() 我使用require()加载标准的全局头文件包含文件

That's where the current default tags are defined. 这就是定义当前默认标签的地方。

IF the URL is public.sample.com/account/Disney, I would like the tag to read, instead: 如果URL是public.sample.com/account/Disney,则我想读取标签,而不是:

This is an account profile for Disney 这是迪士尼的帐户资料

I believe something would need to be written in this global header file, but not sure what. 我相信需要在此全局头文件中编写一些内容,但不确定是什么。

Thanks. 谢谢。

Super simple example to get you started. 超级简单的示例,助您入门。

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

Edited per Allain Lalonde comment. 根据Allain Lalonde评论编辑。 (Hope this is what he meant) (希望这就是他的意思)

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

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

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

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