基本上我有这样的事情如何代码运行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#'上'爆炸'它。 –