PHP regular match between HTML content specified in the wording of PHP regular tag match between the HTML content specified in the label wording

PHP regular match between HTML content specified in the label wording

Assuming that the page reads as follows:

Copy the code
<table>
<tr>
    <td></td>
    <td></td>
</tr>
<tr>
    <td></td>
    <td></td>
</tr>
</table>
Copy the code

I was content to be matched between each <tr> </ tr> (tr course, there are a lot of content, not listed here), not to consider tr nests problems.

Regular first thought is written like this:

preg_match_all( '/<tr[^>]*(.*?)<\/tr>/i', $string, $matches );
echo "<pre>";
print_r( $matches);
echo '</pre>';

But can not run into the following through the Internet to search for information after writing to:

preg_match_all( '/<tr[^>]*([\s\S]*?)<\/tr>/i', $string, $matches );
echo "<pre>";
print_r( $matches);
echo '</pre>';

The reason is simple, back and review on a regular expression shown in [.], [\ S] and [\ S] to know.

Guess you like

Origin www.cnblogs.com/rxbook/p/12470419.html