tag:blogger.com,1999:blog-2793576348171340857.post3575449772367607859..comments2023-10-23T14:33:48.971-07:00Comments on Answers to selected problems: How to get character encoding right in Smartyintjonathanhttp://www.blogger.com/profile/08349837127962896589noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-2793576348171340857.post-37115007656326031472010-05-24T10:17:33.805-07:002010-05-24T10:17:33.805-07:00Thanks for the feedback. I'm making some reall...Thanks for the feedback. I'm making some really key assumptions here that I didn't explain fully - it was 3 years ago, I was a newbie. :)<br /><br />1. I'm assuming that all your templates are encoded in UTF-8.<br />2. I'm assuming all your database fields are collated in UTF-8.<br />3. I'm assuming you're taking all the POSTed form data and converting it to UTF-8 before storing it in the database.<br />4. I'm assuming all your localized string files - whatever mechanism you're using - are encoded in UTF-8. <br />5. I'm assuming you're not using Smarty's built-in escaping mechanism since as you pointed out, it doesn't support UTF-8.<br /><br />The only - and very smallish - problem addressed here is how to get all this lovely UTF-8 data served to a client that doesn't understand it, say it only understands ISO-8859-1. Well you can give it that, and not give it a bunch of characters it doesn't understand, by having them removed in the encoding conversion.intjonathanhttps://www.blogger.com/profile/08349837127962896589noreply@blogger.comtag:blogger.com,1999:blog-2793576348171340857.post-14940968555753711632010-05-24T03:53:16.610-07:002010-05-24T03:53:16.610-07:00Nice article. But I can't see the advantage. C...Nice article. But I can't see the advantage. Converting from ISO-8859-1 to UTF-8 the way you do, just changes the data format, but doesn't expand the available characters. For example, escaping dynamic content for HTML like {$content|escape:'HTML'} will still not be UTF-8 compliant. Actually, smarty will in this case not display anything, if $content contains UTF-8 chars.<br /><br />Going a bit further, converting a page to UTF-8 using your method results in HTML forms to be submitted with UTF-8 encoding. The server-side script will likely not be able to handle that, or at least Smarty will not be able to display it properly, because of the escape:'html' problem described above.<br /><br />In fact, supporting UTF-8 is much more than just converting the template output. You should add a bold WARNING to your article and tell about these disadvantages before they mess up their sites with lots of subtile errors.Trasherhttp://www.trash-factor.comnoreply@blogger.com