开发者

Regex: Extract http and title attributes from anchor tag with PHP

开发者 https://www.devze.com 2023-01-10 06:49 出处:网络
I have a bunch of URLs structured like so <h4 class=\"classname\"><a href=\"http://some-website.com\" onclick=\"someVaryingJS();\" title=\"Some Title\">Some Title</a><h4>

I have a bunch of URLs structured like so

<h4 class="classname"><a href="http://some-website.com" onclick="someVaryingJS();" title="Some Title">Some Title</a><h4>

I want to be able to extract just the href and title attributes, keeping in mind the onclick attribute changes per tag and that I only want to do it for ancho开发者_运维技巧r tags that are within h4's of that class.


You could load the html fragment into DOMDocument, and process it from there..?

It's obviously going to be more flexible, but a lot heavier than a straight up regex.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号