Hi there,
I have a chunk of code that seems to be working, as such:
<?
$set_ID = "CC41";
$hits = 0;
$line_num = 0;
print("<b>The first 4 chars of the code for this playset are $set_ID</b> <br><br>");
if(!($pricelist = @fopen("prices.txt", "r")))
{
print("Sorry, you're screwed. File couldn't be opened.");
exit;
}
while (!feof($pricelist))
{
$this_line = fgets($pricelist, 255);
$line_num = $line_num + 1;
if(preg_match("/($set_ID)(3|4)/", $this_line))
{
preg_match_all("/\$.*(.[0-9]{1,2})/", $this_line, $pricetemp, preg_pattern_order);
$num_prices = count($pricetemp);
print("There should be $num_prices instances of a valid price for code $set_ID on line $line_num. <br>");
print("The first of those is $pricetemp[0]. <br>");
for($i = 0; $i < $num_prices; $i++)
{
$prices[$hits] = $pricetemp[$i];
$hits += 1;
}
}
}
print("<br>Final count of prices in list for code $set_ID was $hits <br>");
fclose($pricelist);
?>
<head>
<title>Price Test 4</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<p>
<?
$num_elements = count($prices);
print ("There are $num_elements prices for this set:<br><br>");
for($x = 0; $x < $num_elements; $x++)
{
$y = $x + 1;
print("Price $y = $prices[$x] <br>");
}
?>
</p>
</body>
As you can imagine, most of this code is to check values and such. The data file I'm using contains these three lines that I'm targeting:
CC412-403 Durango 2 Pos. TL w/ 10 ft. Green Wave Slide "$4,000.00" $550.00
CC413-403 Durango 3 Pos. TL w/ 10 ft. Green Wave Slide "$4,250.00" $800.00
CC414-403 Durango 4 Pos. TL w/ 10 ft. Green Wave Slide "$4,450.00" "$1,000.00"
(the quotes are unavoidable, it seems, given how the folks are generating this text file) I'm trying to get it to pull out the prices from the second and third lines only - that part seems to work. However, when I run it, I get this output:
The first 4 chars of the code for this playset are CC41
There should be 2 instances of a valid price for code CC41 on line 123.
The first of those is Array.
There should be 2 instances of a valid price for code CC41 on line 124.
The first of those is Array.
Final count of prices in list for code CC41 was 4
There are 4 prices for this set:
Price 1 = Array
Price 2 = Array
Price 3 = Array
Price 4 = Array
Tht ain't right. Theoretically, Why is the value of the array being set to "Array" rather than a number? I tried it referencing the 2d arrays that preg_match_all is supposed to create, in every possible format (both preg_set_order and preg_pattern_order, and all combos of $pricetemp[x][y]), and none of them seem to contain any data at all. I thought the actual matching string was supposed to be placed into the array in some capacity, to be easily referenced later. Am I doing something wrong in my expression syntax? Perhaps using preg_match_all is NOT the best way to accomplish this, but the reasoning sounded good. It would be lovely if there were something that would just stick all the matches found into a single dimensional array.
Anyway, does anyone have any ideas about this? Any help would be wonderful. Thank you all for your sage wisdom, and I hope your holidays are proving fun-filled and stress-free.
Matt