在 ThinkPHP 3.2.2 中使用 UEditor 編輯器保存文章內容時,數據庫中保存的數據都被轉義成實體,例如:<p><strong><span style="font-family: 微軟雅黑, 'Microsoft YaHei'; color: rgb(192, 0, 0);"><em><span style="font-family: 微軟雅黑, 'Microsoft YaHei'; text-decoration: underline;">fonts</span></em></span></strong></p>
如圖:
實際上存入的數據是:
那么如果准備在后台編輯已經保存過的數據時,如果不做相應的處理,編輯框內則會出現:
只需要在取出數據時進行相應的處理:
$con['content'] = htmlspecialchars_decode(html_entity_decode($con['content']));
則編輯框內能正確顯示保存的數據:
附:
html_entity_decode():把 HTML 實體轉換為字符,是 htmlentities() 的反函數。
htmlspecialchars_decode(): 把一些預定義的 HTML 實體轉換為字符。
如果是 <textarea> 未經處理存入數據庫的 html 代碼,取出時只需要使用 htmlspecialchars_decode() 函數。