你们在正确的轨道上:-)
这样做的方式如下:
<TITLE><?php echo $metas[ index.php ][ title ]; ?></TITLE>
您可以从 $_SERVER 超级全球数组/变量获得脚本名称 。
另外,从您的 config.php 文件中删除最后三行, 您不需要它们 。
祝你好运,与 PHP 一起确保您对与阵列玩耍有良好的知识。 这是关键 。
编辑:
$page = index.php ;
if ( isset( $_GET[ action ] ) && $_GET[ action ] != "" )
{
$page = $_GET[ action ];
}
<TITLE><?php echo $metas[$page][ title ]; ?></TITLE>
编辑: (on 27th May 2012)
我认为这几乎就是一切:
您在配置.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;
?>