簡體   English   中英

如何解碼用JSON_HEX_QUOT編碼的html字符串 JSON_HEX_TAG

[英]how to decode string of html encoded with JSON_HEX_QUOT | JSON_HEX_TAG

我有由php json_encode和json常量編碼的html

使用json_encode( $data, JSON_HEX_QUOT | JSON_HEX_TAG )

json_encode / json_decode之后和之前

{"agent_designation":"Agent","agent_desc":"\u003Cp\u003EAhmed Khan is a commercial consultant, a B.School MBA with flair of consulting businesses. With insightful perception of end user concerns to methodical compliance in consulting Investor groups, his analytical perspective & proactive approach gave significant recognition. His transparency of information and numbers has gained him virtual clients internationally. He has an unchallenging advantage, in consulting business expansion clients conveying value from concept to completion. His consultation justifies a propertyu2019s relevance, while offering holistic solutions from cost to return on investments.\u003C\/p\u003E","agent_img":"\/wp-content\/uploads\/2015\/09\/Ahmed-Khan-31.jpg","agent_linkedin":"","agent_phone":""}

$data包含在html下方,它可以是帶有單引號,雙引號斜杠或有時只是簡單文本的html。

<p>Ahmed Khan is a commercial consultant, a B.School MBA with flair of consulting businesses. With insightful perception of end user concerns to methodical compliance in consulting Investor groups, his analytical perspective & proactive approach gave significant recognition. His transparency of information and numbers has gained him virtual clients internationally. He has an unchallenging advantage, in consulting business expansion clients conveying value from concept to completion. His consultation justifies a propertyu2019s relevance, while offering holistic solutions from cost to return on investments.</p>

呈現此編碼的html時出現問題,該html顯示( u003Cpu003E )這些類型的字符。

json_decode渲染

        $agent_info = @json_decode( $data );
        echo '<pre>';print_r($agent_info);echo '</pre>';

產量

u003Cpu003EAhmed Khan is a commercial consultant, a B.School MBA with flair of consulting businesses. With insightful perception of end user concerns to methodical compliance in consulting Investor groups, his analytical perspective & proactive approach gave significant recognition. His transparency of information and numbers has gained him virtual clients internationally. He has an unchallenging advantage, in consulting business expansion clients conveying value from concept to completion. His consultation justifies a propertyu2019s relevance, while offering holistic solutions from cost to return on investments.u003C/pu003E

在數據屬性中使用JSON編碼時,規范是不要使用JSON編碼選項轉義,而是轉義HTML屬性的標准機制。 在PHP中,可能帶有諸如htmlspecialchars或htmlspecialentities之類的內容,並且帶有HTML上下文的適當選項。

使用JSON編碼在javascript中嵌入數據時,您只需要JSON_HEX_TAG。

盡管可能會遺漏某些場景或方面,但不要在此引用我的信息。 瀏覽器有一個習慣,即可以繞過某些限制的習慣。 另一方面,我認為以防萬一是合理的。

您可以傳遞JSON_UNESCAPED_UNICODE來輸出原始UTF8,而不是進行轉義。 不過,一些解析器對此表示反對。 您應該檢查標准對此要說些什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM