-2

As html_entity_decode() seems not be the right one - you know how to decode these entities?

ö --> ö 
ä --> ä
ü --> ü

This are only examples - I've no complete list, therefore a general function would be nice - not a char by char replacement.

html_entity_decode() results only in something like ö instead of ö.

Thew
  • 15,789
  • 18
  • 59
  • 100
Petra
  • 565
  • 1
  • 7
  • 20
  • What PHP version are you using? Everything < 5.4.0 will use ISO8859-1, everything >= 5.4.0 UTF-8 as the default encoding. – akluth Oct 22 '13 at 13:25
  • PHP: 5.4.7 - and the html screen is not the problem - I need it as an ö in the database! – Petra Oct 22 '13 at 13:30

1 Answers1

1

you must set your html header to UTF-8 encode!!!

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

see here to change your text encoding on MySQL database: latin-1 to utf-8 database

Community
  • 1
  • 1
Gianluca Ghettini
  • 11,129
  • 19
  • 93
  • 159
  • ...you actually did read the answer, did ya? – akluth Oct 22 '13 at 13:27
  • See above - the html screen is not the problem. I get the string from outside - and need to save it as an ö to the database. – Petra Oct 22 '13 at 13:33
  • @Petra `ü` should decode to "ü" encoded in UTF-8 just fine using `html_entity_decode`. It appears that you're not handling this UTF-8 encoded string correctly afterwards. – deceze Oct 22 '13 at 13:36
  • set your TEXT/VARCHAR/whatever fields to utf-8 instead of latin on MySQL db – Gianluca Ghettini Oct 22 '13 at 13:40
  • @deceze When I save it directly to the DB, I've `ü` in the DB. When I make a html_entity_decode() first and save it to the DB afterwards - the string is cut off before the first umlaut... – Petra Oct 22 '13 at 13:42
  • @G_G It is UTF-8 already. I'm blond but not a noob. ^^ – Petra Oct 22 '13 at 13:44
  • @Petra Again: you are not handling UTF-8 correctly! See http://stackoverflow.com/questions/279170/utf-8-all-the-way-through, [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/), [What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text](http://kunststube.net/encoding/). – deceze Oct 22 '13 at 13:48
  • so be more specific: where exactly do you get the string ö instead of ö? – Gianluca Ghettini Oct 22 '13 at 13:48
  • Sorry... my fault.. on the server was only PHP 5.3.10 - thought it was higher. Therefore he couldn't handle it. As he decodes it as ISO... – Petra Oct 22 '13 at 14:12