word自动消除html标签,移除Remove Microsoft Word HTML Tag

这个代码片段展示了如何使用正则表达式清除从Microsoft Word粘贴到网页时产生的多余HTML标签,如font, span, style和class等。通过删除这些非标准的Word HTML标签,可以确保网页代码的简洁和标准化。
摘要由CSDN通过智能技术生成

移除Remove Microsoft Word HTML Tag

当你使用Microsoft Word会创建许多Tag,比如font,span,style,class等。这些标签对于Word本身而言是非常有用的,但是当你从Word粘贴至网 页时,你会发现很多无用的Tag。因此,下面的这段代码可帮助你删除所有无用的Word HTML Tag。

function cleanHTML($html) {

/// 

/// Removes all FONT and SPAN tags, and all Class and Style attributes.

/// Designed to get rid of non-standard Microsoft Word HTML tags.

/// 

// start by completely removing all unwanted tags

$html = ereg_replace("]*>","",$html);

// then run another pass over the html (twice), removing unwanted attributes

$html = ereg_replace("]*)(class|lang|style|size|face)=("[^"]*"|'[^']*'|[^>]+)([^>]*)>","",$html);

$html = ereg_replace("]*)(class|lang|style|size|face)=("[^"]*"|'[^']*'|[^>]+)([^>]*)>","",$html);

return $html

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值