Domanda

I have upgraded my website to PHP 5.4 and suddenly German umlauts / diacritics which are written as

ö

do not work anymore. They just display as ö instead of ö.

When I go back to PHP 5.3 it works again.

I am preparing the text like this:

$thetext = (html_entity_decode(htmlspecialchars_decode($row[kurztext], ENT_QUOTES)));
È stato utile?

Soluzione

From PHP 5.4 on, htmlentities() and html_entity_decode() are defaulting to 'UTF-8', which probably your data isn't (if it is coming from a database).

See this SO answer for more information.

Note: In that thread, it is just the other way around, so you need to convert your data to UTF-8 or tell the function to interpret your data as non-UTF-8).

$thetext = (html_entity_decode(htmlspecialchars_decode($row[kurztext], ENT_QUOTES), ENT_COMPAT | ENT_HTML401, "ISO-8859-1"));

Additionally, I think you should be able to work without htmlspecialchars_decode() now, since html_entity_decode() can also take care of the quotes via ENT_QUOTES. Just add that additional flag to its parameters (I took the two currently used ones, since they are the PHP default values).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top