我需要为我正在做的脚本动态创建标题,标题应该取决于当前正在使用的文件。
我的结构脚本是:
@require_once"bd.php";
@require_once"Funciones/functions.php";
include head.php;
include body.php;
include footer.php;
我的title函数代码是从head.php调用的
这是我的功能,但不起作用总是返回空白结果:s
function get_title(){
$indexurl = "index.php";
$threadurl = "post.php";
$searchurl = "search.php";
$registerurl = "register.php";
$query = $_SERVER['PHP_SELF'];
$path = pathinfo( $query );
$url = $path['basename']; //This returns the php file that is being used
if(strpos($url,$indexurl)) {
$title = "My home title";
}
if(strpos($url,$threadurl)) {
$title = "My post title";
}
if(strpos($url,$searchurl)) {
$title = "My search title";
}
if(strpos($url,$registerurl)) {
$title = "My register page title";
}
return $title;
}
我调用函数:
<title><? echo get_title(); ?></title>