2 回答

TA貢獻1111條經驗 獲得超0個贊
這是 preg 替換,您可以使用它來刪除所需屬性以外的屬性。
$html = preg_replace("/(<img\\s)[^>]*(src=\\S+)[^>]*(\\/?>)/i", "$1$2$3", $html);
$html = preg_replace("/(<figure\\s)[^>]*[^>]*(\\/?>)/i", "$1$2$3", $html);
$html = preg_replace("/(<figcaption\\s)[^>]*[^>]*(\\/?>)/i", "$1$2$3", $html);
這會給你輸出
<figure ><img src="https://sampleonly.com/wp-content/uploads/2020/01/my-picture-300x169.jpg"><figcaption >This is my picture text.</figcaption><figure>

TA貢獻1982條經驗 獲得超2個贊
您可以使用以下代碼注意:如果您包含 jquery,則僅使用腳本,否則使用下面的 jquery 鏈接
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$('figure,figcaption,img').removeAttr("id style class height width sizes srcset aria-describedby");
</script>
- 2 回答
- 0 關注
- 214 瀏覽
添加回答
舉報