Regular expression to grab form tag content doesn&

2020-07-24 04:22发布

I am trying to grab contents/tags inside form tag using preg_match_all, here is the regular expression

/<form\b[^>]*>(.*?)<\/form>/i

But i wonder, why it doesn't work! Any idea?

2条回答
Luminary・发光体
3楼-- · 2020-07-24 04:46

By default, the . (DOT) does not match line breaks. If you enable DOT-ALL with the s modifier, it does match those chars:

/<form\b[^>]*>(.*?)<\/form>/is

Realize that you won't be able to match something like:

<form>
   ...

   <!-- </form> -->

   ...
</form>

to name just one of the possibilities.

查看更多
登录 后发表回答