【发布时间】:2010-11-29 13:14:48
【问题描述】:
什么是获取两个字符串之间内容的最佳方法,例如
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?
提前致谢!
【问题讨论】:
-
如果它在某些情况下有效而在其他情况下无效,您应该提供示例说明何时有效,何时无效。
标签: php regex file-get-contents output-buffering