Home > Backend Development > PHP Tutorial > 如何用正则匹配带多个属性的html标签

如何用正则匹配带多个属性的html标签

WBOY
Release: 2016-06-13 11:49:29
Original
1169 people have browsed it

怎么用正则匹配带多个属性的html标签
标签各式各样,毫无规律,主要还是属性的顺序不清楚




像这种但是属性顺序不同就有好几种,而且还有分别得到 id href class三种属性值,存到\1 \2 \3中(我用的是preg_replace, 因为要将整个标签替换指定格式)

想了好久不知道这个正则怎么写 望高人帮帮忙

我也想过用 
]*)>匹配到后处理属性,再用str_replace替换回去,但这样重复搜索可能会导致资源开销过大吧   还有什么办法可以实现上面的要求呢?高人帮忙啊
------解决方案--------------------
推荐你学习一下PHPquery的用法,从此采集不需要再用正则
------解决方案--------------------

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template