Jump to content

Encoding/Decoding issues


tua

Recommended Posts

<?php

    $data = ["name" => utf8_encode("Lutz Übelgönner"), "street" => utf8_encode("Änderärger Straße 18")];
    //$data = ["name" => "Bob Smith", "street" => "19 Main Street"];
    $jdata = json_encode($data, JSON_ERROR_UTF8);
    print $jdata;

?>

I do (see code above) in order to be able to json_encode, which gives me:

 

{"name":"Lutz \u00dcbelg\u00f6nner","street":"\u00c4nder\u00e4rger Stra\u00dfe 18"}

 

How do I turn this into something that will make Germans happy?

 

Thanks for any suggestions!

 

Link to comment
Share on other sites

By learning what those \us mean and thereby understanding that they're supposed/allowed to be there? And by saving your file in UTF-8 format and getting rid of those calls to utf8_encode.

 

And by dropping the JSON_ERROR_UTF8. If you look at the documentation you'll see it's not one of the allowed options. And really, it has "error" right there in the name: does that sound right?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.