你走在正确的轨道上:-)
请按以下方式进行:
<TITLE><?php echo $metas['index.php']['title']; ?></TITLE>
您可以从 $_SERVER 超级全局数组/变量中获取脚本名称。
同样从您的 config.php 文件中删除最后 3 行,您不需要它们。
祝你好运,使用 PHP 可以确保你对使用数组有很好的了解。这是关键。
编辑:
$page = 'index.php';
if ( isset( $_GET['action'] ) && $_GET['action'] != "" )
{
$page = $_GET['action'];
}
<TITLE><?php echo $metas[$page]['title']; ?></TITLE>
编辑:(2012 年 5 月 27 日)
我认为这几乎就是一切:
您在 config.php 中的代码
<?php
$meta['INDEX']['title'] = "Home page";
$meta['INDEX']['keywords'] = "kwd1, kwd2, kwd3";
$meta['INDEX']['description'] = "Home description";
$meta['SIGNUP']['title'] = "Sign up..!";
$meta['SIGNUP']['keywords'] = "kwd1, kwd2, kwd3";
$meta['SIGNUP']['description'] = "Sign up description";
$meta['ABOUT']['title'] = "About Company";
$meta['ABOUT']['keywords'] = "kwd1, kwd2, kwd3";
$meta['ABOUT']['description'] = "About company description";
您在任何应用程序页面/屏幕(.php 文件)中的代码:
<?php
include "config.php";
// Choice 1: if you want to specify page hardcoded at each page then you can say $page = 'ABOUT' for about-us page and $page = 'INDEX' for home page etc.
$page = 'ABOUT';
if( strtoupper($_SERVER['REQUEST_URI'], $page) !== false )
{
$title = $meta[$page]['title'];
$keywords = $meta[$page]['keywords'];
$description = $meta[$page]['description'];
}
// Now you have your meta - use it the way you want
echo $title;
// Choice 2: If you want to make it little more dynamic
// Here you don't need to define any hardcoded variable at page level as everything will be considered from the URL being requested
$page_index = array_keys($meta);
foreach($page_index as $page)
{
if ( strpos( strtoupper($_SERVER['REQUEST_URI']), $page ) !== false)
{
$title = $meta[$page]['title'];
$keywords = $meta[$page]['keywords'];
$description = $meta[$page]['description'];
break;
}
}
// Now you have your meta - use it the way you want
echo $title;
?>