I need a regex in php for matching contents between tags of an element, e.g. <body>
and </body>
with the perl compatible preg_match
.
So far I tried with:
// $content is a string with html content
preg_match("/<body(.|\r\n)*\/body>/", $content, $matches);
print_r($matches);
…but the printout is an empty array.
You simply have to add the s
modifier to have the dot match all characters, including new lines :
preg_match("/<body.*\/body>/s", $content, $matches);
as explained in the doc : http://nl2.php.net/manual/en/reference.pcre.pattern.modifiers.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With