如何更改< title>根据URL值在php中动态标记 [英] How can I change the <title> tag dynamically in php based on the URL values

查看:77
本文介绍了如何更改< title>根据URL值在php中动态标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want the title page to be changed so that a crawler can see it.

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

The URL is of the format: public.sample.com/account/Disney

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

I load a standard, global header include file using require()

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

That's where the current default tags are defined.

如果URL是public.sample.com/account/Disney,我希望读取标签,

IF the URL is public.sample.com/account/Disney, I would like the tag to read, instead:

这是迪士尼的帐户资料

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

I believe something would need to be written in this global header file, but not sure what.

谢谢.

推荐答案

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

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>

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

Edited per Allain Lalonde comment. (Hope this is what he meant)

这篇关于如何更改&lt; title&gt;根据URL值在php中动态标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆