c 正则去除a以外的html,正则表达式:去除除SRC以外的HTML属性

这可能会为您的工作需要:

$text = '

This is a paragraph with an image image.jpg

';

echo preg_replace("/]*(\ssrc=['\"][^'\"]*['\"]))?[^>]*?(\/?)>/i",'', $text);

//

This is a paragraph with an image image.jpg

正则表达式细分:

/ # Start Pattern

< # Match '

( # Start Capture Group $1 - Tag Name

[a-z] # Match 'a' through 'z'

[a-z0-9]* # Match 'a' through 'z' or '0' through '9' zero or more times

) # End Capture Group

(?: # Start Non-Capture Group

[^>]* # Match anything other than '>', Zero or More Times

( # Start Capture Group $2 - ' src="...."'

\s # Match one whitespace

src= # Match 'src='

['"] # Match ' or "

[^'"]* # Match anything other than ' or "

['"] # Match ' or "

) # End Capture Group 2

)? # End Non-Capture Group, match group zero or one time

[^>]*? # Match anything other than '>', Zero or More times, not-greedy (wont eat the /)

(\/?) # Capture Group $3 - '/' if it is there

> # Match '>'

/i # End Pattern - Case Insensitive

添加一些报价,并使用替换文本应该从良好剥离任何非src=性质形成了HTML标签。

请注意这不一定要去上ALL投入工作,因为反HTML + RegExp的人都是这样巧妙下面值得注意。在PHP

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值