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

陌路散爱 提交于 2019-12-06 04:27:25

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. (Hope this is what he meant)

im not sure exactly what you are looking for here, but to have a dynamic title you can do:

<title><?php echo $theDynamicTitle; ?></title>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!