dir = self::$REPORT_URL . $dir; } public function setReportDate($the_date) { // Use this function first to set the reporting date you wish to examine // $the_Date in DD-MM-YY format "07-09-09" or "today" if ($the_date == "today") $filename = $this->dir . "/GatewayAPI_" . date ( "d-m-y", time () ) . ".csv"; else { if (count ( explode ( "-", $the_date ) ) < 3) return false; // probably wrong fromat list ( $day, $month, $year ) = explode ( "-", $the_date ); $filename = $this->dir . "/GatewayAPI_$day-$month-$year.csv"; } if ($this->data = file_get_contents ( $filename )) { $this->lines = explode ( "\r\n", $this->data ); return true; } else return false; } public function getWholeReport() { // returns the whole file return $this->data; } public function findNumber($number, $status = false) { // $number is mobile number in international format for example 44777777777 // $status (optional) status can be "d","f","r" for delivered, failed or rejected if ($status) { switch (strtoupper ( $status )) { case "D" : $status = "DELIVERED"; break; case "F" : $status = "FAILED"; break; case "R" : $status = "REJECTED"; break; default : $status = false; } } $found = false; foreach ( $this->lines as $line ) { if (! $status) { if (strstr ( $line, $number ) !== false) $found [] = $this->lineFormat ( $line ); // dont break as there could be more than one instance of the number during the day } else if (strstr ( $line, $number ) !== false and strstr ( $line, $status ) !== false) $found [] = $this->lineFormat ( $line ); } return $found; // return an array of the number keyed array } public function getNextLineArray() // returns a keyed array of each line in the report { $current_arr = each ( $this->lines ); return $this->lineFormat ( $current_arr ['value'] ); } /// PRIVATE FUNCTIONS //// private function lineFormat($line) { list ( $d, $m, $id, $s ) = explode ( ",", $line ); return array ("delivered" => $d, "mobile number" => $m, "message status" => $s ); } } /* EXAMPLE OF USE $reports = new ProcessDeliveryReport ( "Kt65CZMtxlIiEU328ilCBgC38" ); if ($reports->setReportDate ( "20-05-09" )) print_r ( $reports->findNumber ( "44777777777", "r" ) ); else echo "Not found"; */ ?>