PHP:包括页面 - 是否包含 html 标签?

发布于 2024-12-06 06:18:18 字数 288 浏览 2 评论 0原文

我正在为网页设计一个模板,并且正在不同页面中构建模板的单独部分,这些部分将全部包含在一个页面中(即 leftdiv.php、maindiv.php、header.php、footer.php 等) 。该网站将包含希腊字符,我使用 utf-8 编码。

现在我有 leftdiv.php,其中包含希腊字符,但我遗漏了 html &定义页面编码的元标记,因此,我在以正确的编码显示页面时遇到问题,可能是因为当index.php需要leftdiv.php时,没有用于正确编码的元标记。 我是否应该在每个包含的文件上保留元标记?我还有什么其他选择?

I'm designing a template for a webpage and I'm building separate parts of the template in different pages that will all be included in one page (ie, leftdiv.php, maindiv.php, header.php, footer.php etc). The website will contain Greek characters and I'm using utf-8 encoding.

Now I have leftdiv.php which contains greek chars but I've left out the html & meta tags that define the page encoding and as a result, I'm having problems displaying the page in the right encoding, probably because when index.php requires leftdiv.php, there isn't a meta tag for the proper encoding.
Should I leave the meta tags on each included file or not? What other options do I have?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

月光色 2024-12-13 06:18:18

元标签并不重要。

您必须在真实 HTTP 标头中设置编码,而不是在元替换中。
因此,在 PHP 代码中设置编码

header('Content-type: text/html; charset=utf-8');

并保留元标记。

我还想知道为什么你使用这么多模板文件(leftdiv.php、header.php、footer.php 等)而不是将它们全部放在一个主模板中。

Meta tags doesn't matter.

You have to set up encoding in the real HTTP headers, not in meta substitution.
So, set your encoding in the PHP code by

header('Content-type: text/html; charset=utf-8');

and leave meta tags alone.

I am also wondering why you're using so much template files (leftdiv.php, header.php, footer.php etc) instead of placing them all in one main template.

仅一夜美梦 2024-12-13 06:18:18

我的猜测是上传文件时出错了。尝试二进制模式(ftp),因为某些字符可能不是 ascii 字符。

更远;不用担心模板部分中的元标记等;当输出到浏览器时,所有部分都通过 php 连接起来并作为一个 html 页面发送。浏览器对你的不同部分一无所知,只看到整个图片。因此,请在浏览器中检查 html 源代码。如果源已正确标记,并且正确的元标记位于 中,那么一切都应该没问题。要测试它,只需上传一个简单的 html 文件。如果有效,则将其扩展到不同的部分。

My guess is that it goes wrong when uploading the file. Try binary mode (ftp), as some characters may not be ascii chars.

Further; don't worry about meta tags etc. in a template part; when outputting to the browser, all parts are concatenated by php and sent as one html page. The browser doesn't know anything about your different parts, just sees the whole picture. So check the html source in your browser. If the source is properly marked up, and the proper meta tag is in the , everything should be allright. To test it, just upload a simple html file. If it works, then extend it to different parts.

甜柠檬 2024-12-13 06:18:18

您必须在光盘上存储采用 UTF-8 编码的文件。那么元标记就可以了,无需发送额外的标头。

<meta charset="UTF-8" />

You have to store the files with UTF-8 encoding on your disc. Then the meta tag is okay without sending extra header.

<meta charset="UTF-8" />
是伱的 2024-12-13 06:18:18

元标记只能位于页面的头部。我所说的页面指的是 Web 浏览器显示的文档,而不是其背后的 PHP 脚本。因此,不要将元标记放在 footer.php 中。

Meta tags should be only in the head section of a page. And by page I mean the document that is shown by your web browser, not the PHP scripts behind it. So don't put meta tags in footer.php for example.

路还长,别太狂 2024-12-13 06:18:18

浏览器对你的不同部分一无所知,只看到整个图片。因此,请在浏览器中检查 html 源代码。

The browser doesn't know anything about your different parts, just sees the whole picture. So check the html source in your browser.

别念他 2024-12-13 06:18:18

如果您将 header('Content-type: text/html; charset=utf-8'); 设置为使用 UTF-8 编码保存的页面,一切都会好起来的。

if you set header('Content-type: text/html; charset=utf-8'); with page by saved using UTF-8 encoding everything will be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文