Page 1 of 1

RunRev to PHP

Posted: Sat Jul 24, 2010 10:55 am
by shadowslash
I've thought this throughout almost all day but I still can't seem to figure it out..
Can any PHP and RunRev programmer convert this transcript function snippet to a PHP function? Thank you so much!

Code: Select all

function tankTotal pData
   local tMatch,tTotal,tCap,tCap1
   put 0 into tTotal
   put true into tMatch
   repeat until tMatch is false
      put matchChunk(pData,(quote & "cap" & quote & ":" & quote & "([0-9]*[0-9])" & quote),tCap,tCap1) into tMatch
      if tMatch is true then
         get char tCap to tCap1 of pData
         add it to tTotal
         delete char tCap to tCap1 of pData
      end if
   end repeat
   return tTotal
end tankTotal

Re: RunRev to PHP

Posted: Sat Jul 24, 2010 4:28 pm
by mwieder
Totally untested, but I'd try something like the following:
(assuming it's "cap" in quotes, followed by ":" not in quotes, followed by a numeric value in quotes)
(and note the single quotes around the $pattern regex)

Code: Select all

function tankTotal($pData)
{
    $pattern = '"cap":"([0-9]*[0-9])"';
    preg_match_all($pattern, $pData, $amounts);
    $total = 0;
    if (!empty($amounts))
    {
        foreach($amounts as $new_value)
        {
            $total += $new_value;
        }
    }
    return $total;
}