基本上我有這樣的事情如何代碼運行PHP
Hand #1
First row always has the same info,
if the text matches what im looking for ill find
the keyword in the first line. Bunch of text,
bunch more text bla bla bla
Hand #2
這是我的代碼打印出手工#1和手#2
$searchfor = 'myKeyword';
$file = file_get_contents($filename);
// find the location of the keyword, this keyword indicates that i want to grab this group
// of text, since each group of text starts off with Hand #x and ends immediately before the next Hand #x i search for the keyword to identify this is a valid group of text
$pos_keyword = strpos($file, $searchfor);
// there might be a more elegant way but the Hand # value i need will always be within 60-70 characters before the keyword
$rollback = $pos_keyword-100;
// this is the start position of the text i want to grab
$start = strpos($file, "Hand #", $rollback);
// we search from the after the keyword and assign to $end
$end = strpos($file, "Hand #", $pos_keyword);
// print out the string between the start and end Hand# keywords
echo "string: " . substr($file,$start,($end-$start)) . "<br />";
echo "<br /><br /><br />";
之間的所有文字
現在文檔有數百個這些值,我想重複搜索直到文檔結束。我嘗試了谷歌搜索,但人們提到使用!eof($文件)可能會導致循環,我無法讓它工作,任何想法,我會用什麼函數或循環遍歷代碼,直到文檔結束。
我猜我循環,並在最後設置$結束爲新的$ pos_keyword但我不知道什麼樣的循環是最好的使用,任何想法?
你可以在術語'\ nHand#'上'爆炸'它。 –