Jump to content

Looping while condition is set and end on second condition.


w2pc

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.