1

I'm creating a listing website where user can make their titles fancy by using special characters:

in my database i have a field name ads_title varchar(255) latin1_swedish_ci and on my webpage header it says like this

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

when i tested my posting of ads form, i entered in the title this characters ¥šë™test and then when it saves it to the database it turns int olike this šï••

why? how can i save those kind of characters in my dbase at the same time echoing it in php. thanks

Edwin
  • 90
  • 4
  • You should consider switching to utf-8 – Jm Verastigue Jul 16 '13 at 07:09
  • 1
    [UTF-8 all the way through](http://stackoverflow.com/q/279170) – Pekka Jul 16 '13 at 07:10
  • 1
    utf-8 on my database? ok ill try it tnx btw – Edwin Jul 16 '13 at 07:11
  • 2
    In before obligatory [The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)](http://www.joelonsoftware.com/articles/Unicode.html). Or if you don't want to understand what is happening, just make sure everything uses UTF-8. - _"when it saves it to the database it turns into like this"_ - how do you view that? Please make sure that when viewing the data, you're not adding another layer of confusion by forgetting to set the charset somewhere. Anyway see the duplicate question, instructions on setting things up are in there. – CodeCaster Jul 16 '13 at 07:35
  • 1
    [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/), [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Jul 16 '13 at 08:08

1 Answers1

1

As in

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

defining charset of page content or user input as UTF-8 requires database field to have collation UTF-8.

so replace collation latin1_swedish_ci with utf8_swedish_ci ,something that can hold UTF-8 data!

M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
  • sorry im not that really good at database, but which of those utf-8? there is unicode there is swedish spanish, hmm. thanks – Edwin Jul 16 '13 at 07:21
  • I always go with `utf8_general_ci`. They don't differ too much, they just are subsets with certain characters in. There's also `utf8_unicode_ci`, which IIRC is a bit more precise, but a bit slower as well. The 'ci' suffix stands for 'case insensitive', and has to do with the collation used when the database is queried, when a field holds `Foobar` as value, it will match a query for the value 'fooBar' as well. – Pelle Jul 16 '13 at 10:09