5
4

5 回答 5

4

the working solution for me was to follow the twig documentation http://twig.sensiolabs.org/doc/filters/convert_encoding.html

applying a filter {{ field|convert_encoding('UTF-8', ' iso-8859-1') }}

because this often happen when your sub- template is not inheriting the main one , where you had the correct meta charset defined

于 2015-05-04T11:44:23.813 回答
1

I'm not sure that your source data is actually UTF-8 encdoded. var_dump() alone isn't sufficient to verify the encoding of your content.

Try echoing/dumping the content and viewing the page with Firefox or Chrome and change the encoding to UTF-8 and then something else like ISO-8859-1. If your content looks wrong when you have UTF-8 selected then your content is not UTF-8 encoded.

  • To change the encoding in Firefox: View > Character Encoding
  • To change the encoding in Chrome: Tools > Encoding
于 2012-05-17T17:50:56.867 回答
0

I had similar issue and in my case the problem was database encoding mismatch. The solution for me was to use utf8_encode() when first inserting the data into database.

Sample from my code:

// Convert file name into title of template 
$name = str_replace(array('-', '_'), ' ', basename($file, ".html"));
$name = utf8_encode($name);
于 2012-09-13T10:21:11.893 回答
0

mb_detect_encoding($str) is also a method to detect encoding.

http://php.net/mb_detect_encoding

于 2013-03-21T21:51:22.793 回答
0

Try this filter: convert_encoding('UTF-8', 'ISO-8859-1')

于 2017-07-28T02:34:39.230 回答