2

I am using PHP + HTML + smarty (as a template).

There is some dynamic content coming from user's input.

When user enters some special characters for example —.‘@• it's been saved properly in variable.

But when I try to show that same content of special character in textbox (using smarty template) it shows something like this: �.�@�

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> is already included in theHeader`.

I already referred this: utf-8 special characters not displaying

None of its solution worked for me.

Community
  • 1
  • 1
Ruprit
  • 733
  • 1
  • 6
  • 23
  • Are you doing something with the variable like passing it through another function? – Jonathan Apr 27 '15 at 13:22
  • @Augwa: its MVC structure, so am passing the variable from Controller to View(a template) and showing it in `textbox`. When I echo that variable with special characters in a Controller(.php file) its shows up correctly. But when I try to display same thing in smarty-template its shows those wired characters. – Ruprit Apr 28 '15 at 04:58
  • it's quite possible that the function that it's going through converts it to ascii, as such all utf-8 characters are lost. Without more information I don't really have more insight on this, other than you will need to look at the execution chain from where the data gets processed by the smarty template. – Jonathan Apr 28 '15 at 12:32

1 Answers1

0

Make sure that everything that deals with the string supports UTF-8. Mainly:

  • If you store the string in a table before displaying it, check that it is UTF-8 encoded (eg. for MySQL, have DEFAULT CHARSET=utf8 when you create the table).

  • Make sure that the view files are saved as UTF-8. In your text editor, you can normally choose the encoding. Or choose "Save as..." and choose the encoding there.

  • I'm not familiar with Smarty but make sure it's not converting the string to some non-UTF8 encoding.

laurent
  • 88,262
  • 77
  • 290
  • 428
  • Yes, the db table structure have `DEFAULT CHARSET=utf8`. I am using MVC structure, so problem seems when I pass the variable to `View` via `Controller`. Because when I echo that variable with special characters in a Controller(.php file) its shows up correctly but not the template file. – Ruprit Apr 28 '15 at 05:50