如何最好地获取两个字符串之间的内容,例如:
ob_start();
include('externalfile.html'); ## see below
$out = ob_get_contents();
ob_end_clean();
preg_match('/{FINDME}(.|\n*)+{\/FINDME}/',$out,$matches);
$match = $matches[0];
echo $match;
## I have used .|\n* as it needs to check for new lines. Is this correct?
## externalfile.html
{FINDME}
Text Here
{/FINDME}
因为某种原因,这似乎在我的代码中的一个地方起作用,而在另一个地方则不起作用。我这样做对吗?还是有更好的方法?
此外,使用输出缓冲区是做这件事的方式,还是使用file_get_contents?
提前感谢!