Regex: Strip HTML attributes except SRC

前端 未结 6 943
予麋鹿
予麋鹿 2020-12-16 17:13

I\'m trying to write a regular expression that will strip all tag attributes except for the SRC attribute. For example:

6条回答
  •  独厮守ぢ
    2020-12-16 17:30

    You usually should not parse HTML using regular expressions.

    Instead, you should call DOMDocument::loadHTML.
    You can then recurse through the elements in the document and call removeAttribute.

提交回复
热议问题