when writing html form handlers using php, you often need to use regular expressions match input tags in html. this article will introduce how php all < p>
first, we understand some basic knowledge of expressions. regular expression is a pattern used strings, which can help us find, replace and extract specific content text. in preg_match(), preg_match_all(), preg_replace() other functions process
for the needs this article, preg_match_all() function get here sample code: p>
$html="" ; preg_match_all(' ]*> ', $html, $matches); print_r($matches[0]);< pre>
in above code, first define an it. the here run following be output: >array ( [0]=">" " [1]=">" )< div> this array contains tags. we foreach loop iterate through perform further processing on each tag. p> of course, if only tag, also achieve modifying expression. for example, tag expression: >preg_match_all(' ]*type=""email"[^>]*>/'," $matches);< div> the added finally, it should noted although powerful, they prone over-matching or under-matching. actual programming, accuracy stability fully tested verified based conditions ensure correctness robustness program. p>
The above is the detailed content of PHP regular expression: how to match all input tags in HTML. For more information, please follow other related articles on the PHP Chinese website!
]*>< code>, means matching starting with
followed by any number non-
> characters, string ending
>< code>. tags, regardless their type, attributes, values. p>
type=""email"
" qualification condition, indicating that whose attribute email are matched. similarly, combine attributes values to