简体   繁体   English

Smarty模板中的非拉丁字符在使用getDateLocal时显示

[英]Non-latin characters in smarty template showing ���� while using getDateLocal

How can I fix this bug? 如何解决此错误? I am using smarty template. 我正在使用smarty模板。 Here is code: 这是代码:

writeTR2($lngstr['page_visitordetails_startdate'], getDateLocal($lngstr['language']['date_format_full'], $i_rSet1->fields["startdate"]));

The result is 05, 2013 04:16:39 Should be like this Март 05, 2013 04:16:39 结果是 05,2013 04:16:39应该像这样Март05,2013 04:16:39

My database and website are using UTF-8, in other places I do not have this issue everything showing good. 我的数据库和网站都使用UTF-8,在其他地方我没有这个问题,一切都很好。 I mean Cyrillic characters are showing good. 我的意思是西里尔字母显示的很好。 But when I use this function getDateLocal there is a problem. 但是当我使用此函数getDateLocal时出现问题。 When I change the Encoding to Cyrillic(ISO-8859-5) that function shows me character but whole sites showing incorrect. 当我将编码更改为西里尔字母(ISO-8859-5)时,该功能向我显示字符,但整个站点显示不正确。 Help me please. 请帮帮我。

try using the following php function: 尝试使用以下php函数:

convert_cyr_string ( string $str , string $from , string $to )

Refer to http://php.net/manual/en/function.convert-cyr-string.php for more explanation. 有关更多说明,请参考http://php.net/manual/zh/function.convert-cyr-string.php

I don't know getDateLocale in particular, but if it uses the system's locale system, you need to set the locale in an appropriate encoding: 我不特别了解getDateLocale ,但是如果它使用系统的语言环境系统,则需要以适当的编码方式设置语言环境:

setlocale('en_US.UTF8');

Consult your system what locales you have available and in what encoding. 请咨询您的系统,可用的语言环境以及编码方式。

is always indicative of non-UTF-8 characters being displayed in a UTF-8 environment. 始终表示在UTF-8环境中显示非UTF-8字符。 You'd have to either change getDateLocal() 's output to UTF-8, or convert on the fly: 您必须将getDateLocal()的输出更改为UTF-8,或即时进行转换:

$dateLocalConverted = iconv("ISO-8859-5", "UTF-8", getDateLocal($lngstr['language']['date_format_full'], $i_rSet1->fields["startdate"]));

that's a dirty fix, though - it would be best to find out why getDateLocal() is outputting ISO-8859-5 data, and fix that. 但是,这是一个肮脏的解决方案-最好找出getDateLocal()为什么输出ISO-8859-5数据并进行修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM