Json_encode变音符输出 [英] Json_encode umlauts output

查看:79
本文介绍了Json_encode变音符输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用德语变音符号显示输出,例如Fu009 \这样的输出,但是我需要这样的fü".

I want to show my output in German umlauts, i got my output like this for example Fu009\ but i need "fü" like this.

<?php
$json = (object) array(
    "salutation" = > ''.$order - > order_custom_fields['_billing_anrede'][0].
    '',
    "title" = > ''.$order - > order_custom_fields['_billing_titel'][0].
    '',
    "first_name" = > ''.$order - > order_custom_fields['_billing_first_name'][0].
    '',
    "last_name" = > ''.$order - > order_custom_fields['_billing_last_name'][0].
    '',
    "street" = > ''.$order - > order_custom_fields['_billing_address_1'][0].
    '',
    "street_number" = > ''.$order - > order_custom_fields['_billing_address_2'][0].
    '',
    "address_supplement" = > ''.$order - > order_custom_fields['_billing_company'][0].
    '',
    "zipcode" = > ''.$order - > order_custom_fields['_billing_postcode'][0].
    '',
    "city" = > ''.$order - > order_custom_fields['_billing_city'][0].
    '',
    "country" = > ''.$pais.
    '',
    "terms_accepted" = > true,
    "receiving_mails_accepted" = > ''.$email.
    '',
    "email" = > ''.$order - > order_custom_fields['_billing_email'][0].
    '',
    "lottery_accepted" = > false,
    "lottery_solution" = > "LOTTERY",
    "original_created_at" = > ''.date('Y-m-d\TH:i:sP', strtotime($order - > order_date)).
    '',


);

foreach($items as $item) {
    $sku = $wpdb - > get_var($wpdb - > prepare('SELECT meta_value FROM dsr_postmeta WHERE meta_key="_sku" AND post_id='.$item['product_id'].
        ''));
    $sku_s = explode('-', $sku);
    $camp = $sku_s[0];
    $itm_n = $sku_s[1];
    $json - > items[] = (object) array(
        "campaign_number" = > (int) $camp,
        "item_number" = > (int) $itm_n,

    );
}



array_push($json_full, $json);
echo json_encode($json_full);
?>

我正在考虑htmlentities或utf8 谢谢您的帮助!

I'm thinking about htmlentities, or utf8 thanks for you help!!

推荐答案

如果您使用的是PHP 5.4+,请将echo json_encode($json_full);更改为echo json_encode($json_full, JSON_UNESCAPED_UNICODE);

In case you are using PHP 5.4+, change echo json_encode($json_full); to echo json_encode($json_full, JSON_UNESCAPED_UNICODE);

可以在以下位置找到json_encode预定义常量的完整列表: http://lt1.php.net/manual/en/json.constants.php

Full list of json_encode predefined constants can be found there: http://lt1.php.net/manual/en/json.constants.php

代码:

<?php
$json = (object) array(
  "uml" => "fü",
);

echo json_encode($json, JSON_UNESCAPED_UNICODE) . PHP_EOL;

echo json_encode($json) . PHP_EOL;

输出:

{"uml":"fü"}
{"uml":"f\u00fc"}

这篇关于Json_encode变音符输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆