Home  >  Article  >  Backend Development  >  smarty模板输出字符乱码

smarty模板输出字符乱码

WBOY
WBOYOriginal
2016-06-23 13:56:00944browse

我创建了config.conf作为配置文件,想运用smarty模板导入并在页面输出
PHP,html和config.conf为编码方式都为utf8,firefox浏览器unicode
页面却出乱码

我将config.conf改成ANSI编码方式

我推断可能与smarty本身的编码方式有关
我从其他人那里拷贝了一个smarty包(我自己的是从官网上下载最新版本的),页面显示正常没有乱码。

config.conf输入信息如下

webTitle=当当网,全球最大的中文网上书店copyRight=当当网icpNum = 123456


html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><{config_load file="config.conf"}><title><{#webTitle#}></title></head><body><br />---------配置文件demo----------<br /><table align="center" width="400" cellpadding="0" cellspacing="0" border="1">	<tr>		<td>copyright</td>		<td><{#copyRight#}></td>		<td><{#icpNum#}></td>	</tr></table></body></html>


PHP代码
<?php require_once("smarty/Smarty.class.php");$smarty=new Smarty();$smarty->left_delimiter="<{";$smarty->right_delimiter="}>";$smarty->display("index.html");?>


我想问如果还是用原来的smarty包,如何解决以上问题,谢谢各位


回复讨论(解决方案)

把 config.conf 改成无bom的utf-8编码试试。

把 config.conf 改成无bom的utf-8编码试试。



多谢楼上!我看了一些帖子,用记事本保存的是有BOM的,而PHP是不支持BOM的,会导致出错。
最后我通过用PHP保存成PHP文件,修改后缀,错误修正。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn