什麼是獲取兩個字符串之間內容的最佳方式,例如獲取兩個字符串之間的內容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