0
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;
}

有谁知道这个功能是做什么的?

4

2 回答 2

2

好像去掉了

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

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

来自 $this->content 中的文本,并返回这些注释之间的所有文本。

于 2013-08-12T21:57:05.850 回答
2
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.
}

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

于 2013-08-12T22:01:32.223 回答