国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Backend Development PHP Tutorial php json_encode加密后,有的漢字顯示不出來 急解決方法

php json_encode加密后,有的漢字顯示不出來 急解決方法

Jun 13, 2016 pm 12:03 PM
ascii encode json nbsp

php json_encode加密后,有的漢字顯示不出來 急
$e=mb_detect_encoding($str)?輸出個(gè)字符編碼類型,怎么會這樣?
ASCII-------------
UTF-8-------------,王五
UTF-8-------------,趙六
ASCII-------------2014-07-16
-------------電子商務(wù)品牌市場部
-------------工作簡報(bào)
UTF-8-------------未存檔
UTF-8-------------未發(fā)送
-------------經(jīng)理辦公室
ASCII-------------2
UTF-8-------------以后的文號只須選擇文號頭后系統(tǒng)將自動生成
UTF-8-------------我?是?誰
ASCII-------------11
ASCII-------------2014
ASCII-------------
-------------測試部門
ASCII-------------
UTF-8-------------李剛,郭美美,趙智勇,張?zhí)镄?br>ASCII-------------Admin
-------------工作簡報(bào)的總第期數(shù)和當(dāng)年期數(shù)都可以由系統(tǒng)自動生成,生成后在發(fā)文表列表中可以查看
UTF-8-------------研發(fā)中心
-------------集團(tuán)領(lǐng)導(dǎo)
-------------急
UTF-8-------------普通
ASCII-------------
ASCII-------------

使用??json_encode?對數(shù)組加密后,輸出的漢字部分是空的,怎么回事了?
各位大俠們,有沒有好的解決方案??急救


------解決方案--------------------
你原始的數(shù)據(jù)是?gbk?的,這是不能被?json_encode?所接受的
json_encode?只接受?utf-8?編碼的數(shù)據(jù),于是?gbk?漢字因不能識別而丟棄
只有少量的字符組合被錯誤的解釋為?utf-8?雙字節(jié)字符而被保留了下來,造成了你的疑惑不解,要是一個(gè)都不剩的話,反倒使事情明朗化了

所以如果你需要產(chǎn)生?json?的話需要做一下編碼轉(zhuǎn)換

array_walk_recursive($ar, function(&$s) { $s = iconv('gbk', 'utf-8', $s); });

如果數(shù)據(jù)是從 mysql 讀取的,那么只需在讀取前執(zhí)行一次
mysql_query('set names utf8');

就完事大吉了

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization methods for converting PHP arrays to JSON include: using JSON extensions and the json_encode() function; adding the JSON_UNESCAPED_UNICODE option to avoid character escaping; using buffers to improve loop encoding performance; caching JSON encoding results; and considering using a third-party JSON encoding library.

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

Annotations in the Jackson library control JSON serialization and deserialization: Serialization: @JsonIgnore: Ignore the property @JsonProperty: Specify the name @JsonGetter: Use the get method @JsonSetter: Use the set method Deserialization: @JsonIgnoreProperties: Ignore the property @ JsonProperty: Specify name @JsonCreator: Use constructor @JsonDeserialize: Custom logic

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese In-depth understanding of PHP: Implementation method of converting JSON Unicode to Chinese Mar 05, 2024 pm 02:48 PM

In-depth understanding of PHP: Implementation method of converting JSONUnicode to Chinese During development, we often encounter situations where we need to process JSON data, and Unicode encoding in JSON will cause us some problems in some scenarios, especially when Unicode needs to be converted When encoding is converted to Chinese characters. In PHP, there are some methods that can help us achieve this conversion process. A common method will be introduced below and specific code examples will be provided. First, let us first understand the Un in JSON

Quickly learn about ASCII value conversion in PHP Quickly learn about ASCII value conversion in PHP Mar 28, 2024 pm 06:42 PM

ASCII value conversion in PHP is a problem often encountered in programming. ASCII (American Standard Code for Information Interchange) is a standard encoding system for converting characters into numbers. In PHP, we often need to convert between characters and numbers through ASCII code. This article will introduce how to convert ASCII values ??in PHP and give specific code examples. 1. Change the characters

How to use PHP functions to process JSON data? How to use PHP functions to process JSON data? May 04, 2024 pm 03:21 PM

PHP provides the following functions to process JSON data: Parse JSON data: Use json_decode() to convert a JSON string into a PHP array. Create JSON data: Use json_encode() to convert a PHP array or object into a JSON string. Get specific values ??of JSON data: Use PHP array functions to access specific values, such as key-value pairs or array elements.

PHP returns the ASCII value of the first character of the string PHP returns the ASCII value of the first character of the string Mar 21, 2024 am 11:01 AM

This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values ??are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

PHP Tutorial: How to Convert JSON Unicode to Chinese Characters PHP Tutorial: How to Convert JSON Unicode to Chinese Characters Mar 05, 2024 pm 06:36 PM

JSON (JavaScriptObjectNotation) is a lightweight data exchange format commonly used for data exchange between web applications. When processing JSON data, we often encounter Unicode-encoded Chinese characters (such as "u4e2du6587") and need to convert them into readable Chinese characters. In PHP, we can achieve this conversion through some simple methods. Next, we will detail how to convert JSONUnico

See all articles