这个 PHP 正则表达式有什么作用


What does this PHP regular expression do?

public function getBlock( $tag )
   {
     preg_match ('#<!-- START '. $tag . ' -->(.+?)
         <!-- END '. $tag . ' -->#si', $this->content, $tor);
     $tor = str_replace ('<!-- START '. $tag . ' -->', "", $tor[0]);
     $tor = str_replace ('<!-- END '  . $tag . ' -->', "", $tor);
     return $tor;
}

有谁知道这个函数是做什么的?

public function getBlock( $tag )
   {
     //below finds the start tag, then matches any character multiple times
     // until it finds <!-- END $tag -->, store the result in $tor
     preg_match ('#<!-- START '. $tag . ' -->(.+?)
         <!-- END '. $tag . ' -->#si', $this->content, $tor);
     //the # is the delimiter, with s meaning treat as a single line 
     // so . matches 'r'n for example. and i means insensitive 
     $tor = str_replace ('<!-- START '. $tag . ' -->', "", $tor[0]);
     $tor = str_replace ('<!-- END '  . $tag . ' -->', "", $tor);
     //remove the line with start on then remove line with end on.
     return $tor;
     //return what was between the two lines.
}

我在函数中添加了一些注释,希望他们让它更清楚

看起来它删除了

'#<!-- START '. $tag . ' -->'

'<!-- END '  . $tag . ' -->'

从 $this->内容中的文本中返回这些注释之间的所有文本。