这是网站的结构:
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中完成它。
提前完成。
Here is the structure of the web site:
PHP index file
//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 design file
Just the generic structure. Obviously it has a lot more design elements.
<html> <head> ... </head> <body> <?php //this loads the content into the design page include($parameter->content); ?> </body> </html>Question
So here is the problem I experience. The $parameter->content file is a dynamic PHP file, meaning the content also changes according to the query.
For instance if I have a image pages with queries like ?img=1 and ?img=2, my LoadParameter class will only look at the img part of the query and will know that the content of the page should be image.php. image.php however will look at the query again and figure out exactly what image to load.
This causes issues for me because I want to have a different <title></title> for different images. So my solution was just to set the <title></title> element in the content page. This works but it breaks the XHTML markup validation at W3C because it makes the structure of the site to be the following:
<html> <head> ... </head> <body> ... <title>sometitle</title> ... </body> </html>And having <title></title> within <body></body> is not allowed.
So how can I change the title without breaking the XHTML markup validation?
Note: I can't use javascript because then Search engines would not be able to see the title of the page. I need to do it directly in PHP.
Thanx in advance.
最满意答案
为什么不做第二次包括在适当的地方执行标题?
<html> <head> <?php inlcude($parameter->title); ?> ... </head> <body> <?php //this loads the content into the design page include($parameter->content); ?> </body> </html>This is how I solved the issue.
I changed the PHP design to something like:
//get the content PHP file //inside the file I set the following variables //which are used below: //$parameter->title - the string which contains the title //$parameter->html - the string which contains the HTML content include($parameter->content); //string which will contain the html code of the whole page $html = <<<EndHere <html> <head> <title> EndHere; //add title $html .= $parameter->title; $html .= <<<EndHere </title> </head> <body> EndHere; //add the content of the page $html .= $parameter->html; $html .= <<<EndHere </body> </html> EndHere; //output the html echo $html;And here is the basic structure of the Content PHP file. Since the only page which can possibly include the file is the my design page, I can reference $parameter in it.
//set the title $parameter->title = "sometitle"; //set the content HTML $parameter->html = "some HTML here";It's not a very clean solution but it works fine.
更多推荐
发布评论