In php, use regular expressions to find all html tags with id attributes in html. This article gives detailed operation methods. Friends in need can refer to it.
How to use php regular expression to find tags with id attribute in html? That is, you need to find the html tags in angle brackets and id="". For example: String: 123213
21314423
Mismatch:
…… ’s content/div>
The above content can be matched using the following regular rules:
]+?id=[^>]+?>.*?
Here is an example of a complete PHP regular match for HTML tags containing ID attributes.
For example:
<?php $str = '<div style="float:left" id="ab">123213</div><div class="a123">213123</div>'; $search = '#<[a-zA-Z0-9][^>]+?id=[^>]+?>.*?</div>#is'; preg_match_all($search,$str,$r); echo '<pre class="brush:php;toolbar:false">'; print_r($r); echo ' Copy after login Output: Array ( [0] => Array ( [0] => 123213
)
) |