背景:項目中用了富文本編輯器,講寫完的內容存入了數據庫,但是取出的時候因為有些展示地方並不需要樣式,只想獲取到內容,所以需要將帶了html編碼的信息解析出來。
原始信息如下
[task_desc] => <h1 class="mb-5" accuse="qtitle" style="margin: 0px 0px 5px; padding: 0px; word-break: break-all;
"><span class="ask-title" style="display: inline-block; width: 595px; overflow: hidden;
"><span style="font-family:Microsoft YaHei, SimHei, arial;font-size:16px;color:#333333;
"><span style="line-height: 26px;"></span></span></span><h1 class="mb-5"
accuse="qtitle" style="margin: 0px 0px 5px; padding: 0px; word-break: break-all;
"><span class="ask-title" style="display: inline-block; width: 595px; overflow: hidden;
"><span style="font-family: 'Microsoft YaHei', SimHei, arial; color: rgb(51, 51, 51);
"><span style="line-height: 26px; "><span style="font-size:16px;
">詳細解說基因組學和醫學的關系,以及基因組基因功能分類與疾病關系探索。
</span></span></span></span></h1></h1>
1.獲取的時候通過php的htmlspecialchars_decode()函數將信息里的 <內容轉換成html的標記,再通過strip_tags()將html標記去除就可以獲取到干凈的內容了。
task_arr[$k]['task_desc'] = strip_tags(htmlspecialchars_decode($v['task_desc']));
轉載:https://blog.csdn.net/cdy102688/article/details/38257689