Home > Backend Development > PHP Tutorial > PHP regular search for html tags containing id attributes in html

PHP regular search for html tags containing id attributes in html

WBOY
Release: 2016-07-25 08:52:21
Original
2311 people have browsed it
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
)

)



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