【发布时间】:2010-12-30 18:55:34
【问题描述】:
这是网站的结构:
PHP 索引文件
//my class for analyzing the PHP query
$parameter = new LoadParameters();
//what this does is it accesses the database
//and according to the query, figures out what should be
//loaded on the page
//some of the things it sets are:
// $parameter->design - PHP file which contains the design
// HTML code of the page
// $parameter->content - Different PHP file which should be loaded
// inside the design file
$parameter->mysqlGetInfo($_SERVER['QUERY_STRING']);
//load the design file
include($parameter->design);
PHP 设计文件
只是通用结构。显然它有更多的设计元素。
<html>
<head>
...
</head>
<body>
<?php
//this loads the content into the design page
include($parameter->content);
?>
</body>
</html>
问题
这就是我遇到的问题。 $parameter->content 文件是一个动态的 PHP 文件,这意味着内容也会根据查询而变化。
例如,如果我有一个带有 ?img=1 和 ?img=2 之类查询的图像页面,我的 LoadParameter 类将只查看查询的 img 部分,并且知道页面的内容应该是image.php。 image.php 但是会再次查看查询并确定要加载的确切图像。
这给我带来了问题,因为我想为不同的图像使用不同的 <title></title>。所以我的解决方案就是在内容页面中设置<title></title> 元素。这可行,但它破坏了W3C 处的 XHTML 标记验证,因为它使网站的结构如下:
<html>
<head>
...
</head>
<body>
...
<title>sometitle</title>
...
</body>
</html>
并且不允许在<body></body> 中包含<title></title>。
那么如何在不破坏 XHTML 标记验证的情况下更改标题?
注意:我不能使用 javascript,因为这样搜索引擎将无法看到页面的标题。我需要直接在 PHP 中完成。
提前感谢。
【问题讨论】:
标签: php validation title xhtml