包含标题,如何?
<html>
<head>
<!--#include virtual="header.php" -->
</head>
<body>
aa
</body>
</html>
我试图将标头放入不同的文件中并使用包含来调用它。但我无法让它发挥作用。现在标题中唯一的文本是单词标题。标题位于:www.chusmix.com/game/header.php 我该如何调用它?我不在乎是否使用 include virtual,我只是不知道该怎么做。
谢谢
<html>
<head>
<!--#include virtual="header.php" -->
</head>
<body>
aa
</body>
</html>
I'm trying to put the header in a different file and call it with an include. But I can't make it work. Right now the only text in the header is the word header. The header is at: www.chusmix.com/game/header.php how can I call it? I don't care if I use include virtual, I just don't know how to do it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要将其包含在 php 代码中:
You need to include it in the php code:
您的包含需要在 PHP 中——您尝试包含它的方式是 SSI(服务器端包含)的一种非常古老的方法,与 PHP 无关。
为了以这种方式包含,执行包含的页面必须解析为 PHP,并且在大多数服务器上,这意味着文件名以 .php 扩展名结尾。您可以在 .php 文件中包含纯 HTML,这样您只需将该文件(如果还没有)重命名为 .php,然后包含我上面写的行即可。
Your include needs to be in PHP -- the way you attempted to include it is a very old method of SSI (sever side includes) and has nothing to do with PHP.
In order to include this way, the page doing the including must be parsed as PHP, and on most servers that means ending the filename with a .php extension. You can have plain HTML in a .php file so you can just rename the file (if its not already) to .php and then include the line I wrote above.
随意选择;)
澄清一下:include 和 require 的区别仅在于,如果文件不存在,include 只会显示警告,而 require 会抛出致命错误。
另一方面, *_once 函数确保文件仅包含一次。尝试包含同一文件两次,您会收到错误。 *_once 确保“包含”仅执行一次。
另一方面, *_once 函数会给您带来一些开销,但在编写更大的应用程序时应该考虑到这一点。
take your pick ;)
To clarify: include and require differ only as much, that if file does not exist, include will only display warning, while require will throw fatal error.
The *_once functions on the other hands make sure file is included only once. Try including the same file two times, you'll get an error. *_once makes sure the 'including' is done only once.
On the other hand, *_once functions bring you a bit of overhead, but that should be taken in account when writing bigger applications.