例如它的工作原理:
{<div\s+class=\"article\"><h2(.*)</div>}s
如果我这样做,我什么也得不到:
{<div\s+class=\"article\">
<h2(.*)
</div>}s
我怀疑我应该使用一些修饰符,但我从这里知道哪一个:http: //php.net/manual/en/reference.pcre.pattern.modifiers.php
例如它的工作原理:
{<div\s+class=\"article\"><h2(.*)</div>}s
如果我这样做,我什么也得不到:
{<div\s+class=\"article\">
<h2(.*)
</div>}s
我怀疑我应该使用一些修饰符,但我从这里知道哪一个:http: //php.net/manual/en/reference.pcre.pattern.modifiers.php
那将是/x
修饰符:
x (PCRE_EXTENDED)
如果设置了此修饰符,则模式中的空白数据字符将被完全忽略,除非转义或在字符类内,并且字符类外未转义的 # 和下一个换行符(包括在内)之间的字符也将被忽略。这相当于 Perl 的 /x 修饰符,并且可以在复杂模式中包含注释。但是请注意,这仅适用于数据字符。空白字符可能永远不会出现在模式中的特殊字符序列中,例如在序列 (?( 它引入了条件子模式。
它还允许注释模式,这非常有用:
{<div\s+class=\"article\"> # many spaces between the div and the attribute
<h2(.*) # don't really care about closing the tag
</div>}sx