PHP如何讓json_encode不轉義中文?
PHP讓json_encode不轉義中文的方法:在使用“json_encode()”函數進行JSON編碼時,在第2個參數傳入常數“JSON_UNESCAPED_UNICODE”,其意義是以字面編碼多位元組Unicode字元。
程式碼範例
$jsonStr = json_encode($data,JSON_UNESCAPED_UNICODE);
JSON 預先定義常數
JSON_ERROR_NONE (integer)
沒有錯誤發生。自 PHP 5.3.0 起生效。
JSON_ERROR_DEPTH (integer)
到達了最大堆疊深度。自 PHP 5.3.0 起生效。
JSON_ERROR_STATE_MISMATCH (integer)
出現了下溢(underflow)或模式不符。自 PHP 5.3.0 起生效。
JSON_ERROR_CTRL_CHAR (integer)
控製字元錯誤,可能是編碼不對。自 PHP 5.3.0 起生效。
JSON_ERROR_SYNTAX (integer)
語法錯誤。自 PHP 5.3.0 起生效。
JSON_ERROR_UTF8 (integer)
異常的 UTF-8 字符,也許是因為不正確的編碼。自 PHP 5.3.3 起生效。
JSON_ERROR_RECURSION (integer)
The object or array passed to json_encode() include recursive references and cannot be encoded. If the JSON_PARTIAL_PUT_ON_ERROR reference. Available since PHP 5.5.0.
JSON_ERROR_INF_OR_NAN (integer)
The value passed to json_encode() includes either NAN or INF. If the JSON_PARTIAL_OUT UT_PARTIbe the place of these special numbers. Available since PHP 5.5.0.
JSON_ERROR_UNSUPPORTED_TYPE (integer)
#A value of an unsupported type was given to json_
#A value of an unsupported type was given to json_encode(), resource the as a JSON_PARTIAL_OUTPUT_ON_ERROR option was given, NULL will be encoded in the place of the unsupported value. Available since PHP 5.5.0.JSON_ERROR_INVALID_PROPERPER 5.5.0.JSON_ERROR_INVALID_PROPERPER_N string passed to json_decode() when decoding a JSON object into a PHP object. Available since PHP 7.0.0.##JSON_ERROR_UTF16 (integer)
#S unpaired UTFingle-16 surrogate the JSON string passed to json_encode(). Available since PHP 7.0.0.
下面的常數可以和json_decode() 的form 選項結合使用。
JSON_BIGINT_AS_STRING (integer)
將大數字編碼成原始字元原來的值。自 PHP 5.4.0 起生效。
JSON_OBJECT_AS_ARRAY (integer)
Decodes JSON objects as PHP array. This option can be added automatically by calling json_decode() with the second parameter equal to TR. Available.
##下面的常數可以和json_encode() 的form 選項結合使用。 JSON_HEX_TAG (integer)所有的 轉換成 \u003C 和 \u003E。自 PHP 5.3.0 起生效。 JSON_HEX_AMP (integer)所有的 & 轉換成 \u0026。自 PHP 5.3.0 起生效。 JSON_HEX_APOS (integer)所有的 ' 轉換成 \u0027。自 PHP 5.3.0 起生效。 JSON_HEX_QUOT (integer)所有的" 轉換成\u0022。自PHP 5.3.0 起生效。JSON_FORCE_OBJECT (integer)#使一個使一個非關聯陣列輸出一個類別(Object)而非陣列。在陣列為空而接受者需要一個類別(Object)的時候尤其有用。自PHP 5.3.0 起生效。JSON_NUMERIC_CHECK (integer)將所有數字字串編碼成數字(numbers)。自PHP 5.3.3 起生效。JSON_PRETTY_PRINT (integer) 用空白字元格式化傳回的資料。自PHP 5.4.0 起生效。JSON_UNESCAPED_SLASHES (integer)不要編碼/。 自PHP 5.4.0 起生效。JSON_UNESCAPED_UNICODE (integer) 以字面編碼多位元組Unicode 字元(預設是編碼成\uXXXX)。自PHP 5.4.0 起生效。JSON_PARTIAL_OUTPUT_ON_ERROR (integer)#Substitute some unencodable values instead of failing . Available since PHP 5.5.0.JSON_PRESERVE_ZERO_FRACTION (integer)Ensures that float values are always encoded as a float value. Available since PHP 5.6.6 (integer)The line terminators are kept unescaped when JSON_UNESCAPED_UNICODE is supplied. It uses the same behaviour as it was before PHP 7.1 without this constant. Available since#7.1.#. :《PHP
》以上是PHP如何讓json_encode不轉義中文?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文比較了酸和基本數據庫模型,詳細介紹了它們的特徵和適當的用例。酸優先確定數據完整性和一致性,適合財務和電子商務應用程序,而基礎則側重於可用性和

本文討論了確保PHP文件上傳的確保,以防止諸如代碼注入之類的漏洞。它專注於文件類型驗證,安全存儲和錯誤處理以增強應用程序安全性。

本文討論了在PHP中實施API速率限制的策略,包括諸如令牌桶和漏水桶等算法,以及使用Symfony/Rate-limimiter之類的庫。它還涵蓋監視,動態調整速率限制和手

本文討論了使用password_hash和pyspasswify在PHP中使用密碼的好處。主要論點是,這些功能通過自動鹽,強大的哈希算法和SECH來增強密碼保護

本文討論了OWASP在PHP和緩解策略中的十大漏洞。關鍵問題包括注射,驗證損壞和XSS,並提供用於監視和保護PHP應用程序的推薦工具。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)