w2pc Posted November 9, 2010 Share Posted November 9, 2010 I have the following functions that i need to only loop if the conditions are true. The conditions are based on a 2 preg_match: # if so it should loop between Dispursments that start between # preg_match('/W2PC/',$cell->nodeValue); # and the next # preg_match('/TOTAL FOR W2PC/',$cell->nodeValue); The loop should start at the first and end when it identifies the second preg_match. While the conditions are true, it needs to append 'W2PC' to array_push($receipts[$inny],$nodeValue); // I got this to work array_push($receipts[$inny],$nodeValue .' W2PC'); It just does not stop after the ending total preg_match Below is the function and I would like to know where and how I should structure my loop to only function during the above preg_matchs every element is a cell: this is done with the following in a parent function: $dom = new DOMDocument(); @$dom->loadHTML($html); $xpath = new DOMXPath($dom); $tables = $dom->getElementsByTagName("table"); -------------------------------------------------------------------------- THE TABLE LOOKS LIKE THIS -------------------------------------------------------------------------- DATE CODE DESCRIPTION AMOUNT TERM CREDNO/CLM CHECK NO -------------------------------------------------------------------------------------- W2PC Nov 20, 2009 ATF CONSULT'S FEE $439.55 T99 008640/0000 5649174 Jan 22, 2010 ATF CONSULT'S FEE $424.54 T99 008640/0000 5658412 Feb 26, 2010 ATF CONSULT'S FEE $212.36 T99 008640/0000 5663300 Mar 26, 2010 ATF CONSULT'S FEE $636.80 T99 008640/0000 5668325 May 28, 2010 ATF CONSULT'S FEE $849.07 T99 008640/0000 5677844 Jun 25, 2010 ATF CONSULT'S FEE $17.68 T99 008640/0000 5682804 TOTAL FOR W2PC $2,580.00 --------------------------------------------------------------------------------------- SECOND PAYEE Nov 20, 2009 NOTF NOTICE FEES $15.66 T99 700000/0000 5649993 TOTAL FOR SECOND PAYEE $15.66 --------------------------------------------------------------------------------------- Right now the code grabs the atf fees and the notf from the second payee ---------------------------THE FUNCTION----------------------------------------------- function getPayments($tables,$tableId){ $receipts = array(); $outty = 1; $inny = 0; foreach($tables->item($tableId)->childNodes as $rowId=>$row) { if($row->childNodes){ foreach($row->childNodes as $idx=>$cell) { if($cell->nodeType==XML_ELEMENT_NODE && !preg_match('/^Â/',trim($cell->nodeValue)) && trim($cell->nodeValue) != '') { $nodeValue = preg_replace('/Â/','',trim($cell->nodeValue)); //echo "TableID: $tableId RowId: $rowId CellId: $idx<br>" .$nodeValue. "<br><br><br>"; if(!isset($receipts[$inny])){ //** check first word, should only be 3 chars long **// list($fword) = preg_split('/(\s+| )/',$nodeValue); if(strlen($fword) != 3){ continue; }else{ $receipts[$inny] = array($nodeValue); } }else{ array_push($receipts[$inny],$nodeValue); } //* if it is divisible by 5 then we need to incrment our array pointer *// if(($outty % 5) == 0) $inny++; $outty++; } } } } return $receipts; } Link to comment https://forums.phpfreaks.com/topic/218176-looping-while-condition-is-set-and-end-on-second-condition/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.