什么是获取两个字符串之间内容的最佳方式,例如获取两个字符串之间的内容PHP
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?
在此先感谢!
如果它在某些情况下有效,而不是其他情况,则应提供何时有效以及何时无效的示例。 – Welbog 2009-09-18 16:08:55