Output file of a while loop
Posted: Thu Mar 08, 2012 1:14 pm
Hi I am a new php developer that is having some issue with a part of code that I wrote. I listed my script in another forum post but I think i could be a bit more specific with the issue I am having. So i know the code finds the searchString I am looking for, and pulls it correctly the first time. The issue is that it continues to run, though I know the loop I created will pull all matching statements. Now one thing I tried was to look for a more unique code in the html site I was using, with no good feedback. If anyone could give me some advice on what I could do that be helpful.
part of the code
The output file looks something like this:
part of the code
Code: Select all
$index = stripos($fileContents, $searchString);
while ($index !== false) {
if ($index >= 0) {
//if ($debug) {
print "endString: " . $endString . "\n";
print "startIndex: " . ($index+strlen($searchString)) . " " . strlen($fileContents) . "\n";
//}
$endIndex = stripos($fileContents, $endString, $index+strlen($searchString));
if ($debug) {
print "endIndex: " . $endIndex . "\n";
print " index: " . ($index+strlen($searchString)) . "\n";
print "endIndex: " . ($endIndex - ($index+strlen($searchString))) . "\n";
}
$price = trim(substr($fileContents, $index+strlen($searchString), $endIndex - ($index+strlen($searchString))));
if ($debug) {
print "\n******** PRICE: *********************************" . $price . "\n";
}
}
$dollarSignIndex = stripos($price,$endString, "\$");
if ($i2 == 0 || $dollarSignIndex === false) {
if (strlen($priceString) > 0) {
$priceString .= "|";
}
$priceString .= $price;
}
Code: Select all
<tr>
<td class="priceBlockLabel">Issues:</td>
<td>12
******** searchString: <td> ********************************* index: 81480
endString: issues / 12 months</td>
startIndex: 111679 204556
endIndex: 111681
index: 111679
endIndex: 2
******** PRICE: *********************************12
******** searchString: <td> ********************************* index: 111675
endString: issues / 12 months</td>
startIndex: 112322 204556
endIndex:
index: 112322
endIndex: -112322
******** PRICE: *********************************
******** searchString: <td> ********************************* index: 112318
endString: issues / 12 months</td>
startIndex: 115996 204556
endIndex:
index: 115996
endIndex: -115996
******** PRICE: *********************************