View previous topic :: View next topic |
Author |
Message |
EXEMOK Smarty n00b
Joined: 14 Nov 2013 Posts: 4
|
Posted: Thu Nov 14, 2013 9:05 am Post subject: Problem with html_options in PHP >= 5.4 |
|
|
So, our production server upgraded to PHP 5.4.
Smarty version 3.1.15.
After that we have problems with Cyrilic letters in html_options
PHP code:
$arr = [
"индекс" => "значение",
"индекс1" => "значение1",
"index" => "value",
];
$smarty->assign('arr', $arr);
$smarty->display('test.tpl');
smarty code:
{html_options options=$arr name=a id=a}
html output is:
<select name="a" id="a">
<option value="" id="a-0"></option>
<option value="" id="a-1"></option>
<option value="index" id="a-2">value</option>
</select>
So no value when cyrylic letters.
Same code on php 5.2 works fine
Where to dig?
For example this code display russian letters correct:
{foreach from=$arr key=key item=item}
{$key}
{$item}
{/foreach}
Last edited by EXEMOK on Thu Nov 14, 2013 1:42 pm; edited 1 time in total |
|
Back to top |
|
EXEMOK Smarty n00b
Joined: 14 Nov 2013 Posts: 4
|
Posted: Thu Nov 14, 2013 10:08 am Post subject: |
|
|
So, I fixed it, probably strange way.
In PHP 5.4 behavior of html_specialchars() changed, and it is now UTF8 as default.
It is called in shared.escape_special_chars.php
The only solution I found is before starting SMARTY assign:
define('SMARTY_RESOURCE_CHAR_SET', 'cp1251');
If anybody knows more pretty solution - please let me know.
Thanks in advance. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 14, 2013 1:19 pm Post subject: |
|
|
As it looks like you did not store your PHP script file which does define your $arr array with Cyrilic strings in UTF-8 format.. |
|
Back to top |
|
EXEMOK Smarty n00b
Joined: 14 Nov 2013 Posts: 4
|
Posted: Thu Nov 14, 2013 1:21 pm Post subject: |
|
|
U.Tews wrote: | As it looks like you did not store your PHP script file which does define your $arr array with Cyrilic strings in UTF-8 format.. |
For sure - no. So php >=5.4 doesn't work with encodings other then UTF8? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 14, 2013 2:03 pm Post subject: |
|
|
htmlspecialchars() does now use the charset defined by 'SMARTY_RESOURCE_CHAR_SET' (default is UTF-
If you have Cyrilic quoted strings also in your PHP files, you must save the PHP files also in the charset of 'SMARTY_RESOURCE_CHAR_SET'.
Last edited by U.Tews on Thu Nov 14, 2013 2:06 pm; edited 1 time in total |
|
Back to top |
|
EXEMOK Smarty n00b
Joined: 14 Nov 2013 Posts: 4
|
Posted: Thu Nov 14, 2013 2:05 pm Post subject: |
|
|
So, If I do not want (to much work right now) to change charset of PHP files is my solution - define('SMARTY_RESOURCE_CHAR_SET', 'cp1251') - right? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Nov 14, 2013 2:09 pm Post subject: |
|
|
'SMARTY_RESOURCE_CHAR_SET' , the template source and PHP script files charsets must just be the same. |
|
Back to top |
|
neven Smarty n00b
Joined: 23 Apr 2015 Posts: 1
|
Posted: Thu Apr 23, 2015 9:45 am Post subject: |
|
|
In shared.escape_special_chars.php
change
$string = htmlspecialchars($string);
to
$string = htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'cp1251'); |
|
Back to top |
|
|