一个 HTML 页面中可以使用多种字符编码吗?
我有一个设置为 UTF-8 的网页。但其部分内容(内置于 php)来自 iso-8859-1 文件,因此无法正确显示。
是否可以为特定页面元素设置特定编码?
I have a webpage that is set to UTF-8. But parts of its content (built in php) come from iso-8859-1 files and are thus not displayed correctly.
Is it possible to set a specific encoding for a particular page element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过转换脚本传递 php 输出,而不是直接包含该输出。
PhP 有一个不错的转换函数mb_convert_encoding,可以使任务更容易。
You could, instead of including that output directly, pass that php output through a conversion script.
PhP has a decent conversion function mb_convert_encoding that could make the task easier.
不,我认为这是不可能的。由于您已在页面内使用 UTF-8,因此在读取其他页面的内容时如果得到意外结果,则一定存在问题。您不应在使用 UTF-8 页面时遇到任何问题。
No, I don't think this can be done. Since you already use UTF-8 inside the page, there must be something wrong while reading the content from other pages if you get unexpected results. You shouldn't experience any problems with a UTF-8 page.
不可以,一页上只能使用一种编码。您可能希望将 iso 内容编码为由 PHP 生成的实体。
No, only a single encoding can be used on one page. You might want to encode your iso-stuff to entities that's generated by PHP.
您最终可能会使用 iframe 来显示其他内容,以便您可以为所需的字符编码设置元标记。
You may end up using an iframe to display the other content so you can set your meta tag for the character encoding you need.
您如何将 Latin-1 文件插入页面?如果您将它们作为文本加载,然后将它们作为文本包含在内,那么我希望将为您执行相关转换。如果您只是包含文件而不进行任何转换,那么这确实是一个问题。
我不知道 PHP 使用什么作为其内部文本格式(例如 Unicode),但如果您可以使用它作为中间编码,那就应该没问题。
How are you inserting the Latin-1 files into the page? If you're loading them as text and then including them as text, then I'd hope the relevant conversion would be performed for you. If you're just including the files without any transformation, that would indeed be an issue.
I don't know what PHP uses as its internal text format (e.g. Unicode) but if you can use that as an intermediate encoding, it should be okay.