我想实现一个网站上翻译,我尝试在http://we-love-php.blogspot.com.ar/2012/07/how-to-implement-i18n-without.html来自包含页面的PHP返回方法?
找到了方法,我可以轻松地做到这一点,当请求的页面是一个完整的页面,但我不知道该怎么办时,请求的页面由许多包含的文件组成。
这里就是我的index.php样子:
<?php
include 'includes/header.php';
include 'includes/index.php';
include 'includes/footer.php';
?>
而我已经试过是把类中的每个模板文件是这样的:
<?php
class example{
public function now() {
return <<<FOOBAR
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MY SITE's TITLE</title>
<meta name="keywords" content="SOME KEYWORDS" />
<meta name="description" content="SOME DESCRIPTION">
<meta name="author" content="MY NAME">
...........
FOOBAR;
}
}
?>
这没”因为它试图不止一次地创建这个类。然后我试着在头上创建类,然后在页脚后关闭它。它给我一个错误,就好像PHP试图首先打开页脚一样,然后我重新排列了包含文件的顺序,所以它包含了footer.php和header.php。不仅它出现乱七八糟,而且在底部有一条警告信息说:
Parse error: syntax error, unexpected end of file, expecting variable
我该如何解决这个问题?我喜欢这种翻译我的网站的方法,但需要它在包含模板的同时工作。可能吗?
在此先感谢!