Valentino Ru Valentino Ru - 1 year ago 127
JSON Question

problems with german umlauts in php json_encode

I'm getting troubles with data from a database containing german umlauts. Basically, whenever I receive a data containing umlauts, it is a black square with an interrogation mark. I solved this by putting

mysql_query ('SET NAMES utf8')

before the query.

The problem is, as soon as I use
on a result of a query, the value containing an umlaut gets
. I can see this by calling the php-file directly in the browser. Are there other solution than replacing this characters before encoding to JSON and decoding it in JS?

Answer Source

You probably just want to show the texts somehow in the browser, so one option would be to change the umlauts to HTML entities by using htmlentities().

The following test worked for me:

    $test = array( 'bla' => 'äöü' );
    $test['bla'] = htmlentities( $test['bla'] );

    echo json_encode( $test );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download