Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Problem with html_options in PHP >= 5.4

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
EXEMOK
Smarty n00b


Joined: 14 Nov 2013
Posts: 4

PostPosted: Thu Nov 14, 2013 9:05 am    Post subject: Problem with html_options in PHP >= 5.4 Reply with quote

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
View user's profile Send private message
EXEMOK
Smarty n00b


Joined: 14 Nov 2013
Posts: 4

PostPosted: Thu Nov 14, 2013 10:08 am    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Nov 14, 2013 1:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
EXEMOK
Smarty n00b


Joined: 14 Nov 2013
Posts: 4

PostPosted: Thu Nov 14, 2013 1:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Nov 14, 2013 2:03 pm    Post subject: Reply with quote

htmlspecialchars() does now use the charset defined by 'SMARTY_RESOURCE_CHAR_SET' (default is UTF-Cool

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
View user's profile Send private message
EXEMOK
Smarty n00b


Joined: 14 Nov 2013
Posts: 4

PostPosted: Thu Nov 14, 2013 2:05 pm    Post subject: Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu Nov 14, 2013 2:09 pm    Post subject: Reply with quote

'SMARTY_RESOURCE_CHAR_SET' , the template source and PHP script files charsets must just be the same.
Back to top
View user's profile Send private message
neven
Smarty n00b


Joined: 23 Apr 2015
Posts: 1

PostPosted: Thu Apr 23, 2015 9:45 am    Post subject: Reply with quote

In shared.escape_special_chars.php
change

$string = htmlspecialchars($string);

to

$string = htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'cp1251');
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP