天天看點

html 實體轉換為字元:轉換 UEditor 編輯器

編輯器裡輸入的送出後,輸出時,帶有<br>

檢視表中,都是實體。

解決辦法:在輸出前将内容轉換即可。

htmlspecialchars_decode()

需要再詳細,請閱讀如下:

在 ThinkPHP 3.2.2 中使用 UEditor

編輯器儲存文章内容時,資料庫中儲存的資料都被轉義成實體,例如:&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;&amp;lt;span

style=&amp;quot;font-family: 微軟雅黑, &amp;amp;#39;Microsoft

YaHei&amp;amp;#39;; color: rgb(192, 0,

0);&amp;quot;&amp;gt;&amp;lt;em&amp;gt;&amp;lt;span

style=&amp;quot;font-family: 微軟雅黑, &amp;amp;#39;Microsoft

YaHei&amp;amp;#39;; text-decoration:

underline;&amp;quot;&amp;gt;fonts&amp;lt;/span&amp;gt;&amp;lt;/em&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;

如圖:

html 實體轉換為字元:轉換 UEditor 編輯器
實際上存入的資料是:
html 實體轉換為字元:轉換 UEditor 編輯器
那麼如果準備在背景編輯已經儲存過的資料時,如果不做相應的處理,編輯框内則會出現:
html 實體轉換為字元:轉換 UEditor 編輯器
隻需要在取出資料時進行相應的處理:

$con['content'] = htmlspecialchars_decode(html_entity_decode($con['content']));      

則編輯框内能正确顯示儲存的資料:

html 實體轉換為字元:轉換 UEditor 編輯器

附:

html_entity_decode():把 HTML 實體轉換為字元,是 htmlentities() 的反函數。