Re: Help with collecting data from an e-mail
| From: | Jack Lauman | Date: | Sat, 19 Aug 2000 07:06:43 +0000 |
| Subject: | Re: Help with collecting data from an e-mail | ||
| References: | 1 2 | Groups: | php.db php.general |
| Request: | Send a blank email to php-db+get-2179@lists.php.net to get a copy of this message | ||
I'm trying to read an e-mail, ignore the headers, and extract 6 pieces
of information. If I manually delete all the header and trailer info
the code below works fine. However there is a new email on a daily
basis and I can't figure out how to tell php to scan the file ignore
to junk and grab what I want.
<---e-mail snip--->
<I need to ignore all the header info and extract the date and time
from the line below>
Rates as of 1999.06.18 13:10:06 UTC (GMT). Base currency is USD.
<I need to ignore the next tow lines and begin extracting the four
fields beginning on the third line and continue to the message trailer
which also needs to be ignored>
Currency Unit USD/Unit Units/USD
================================ ===================
===================
USD United States Dollars 1.00000
1.00000
EUR Euro 1.04049
0.961084
GBP United Kingdom Pounds 1.59528
0.626851
CAD Canada Dollars 0.682719
1.46473
DEM Germany Deutsche Marks 0.531995
1.87972
<---end--->
I would appreciate any help that can be offerd to help resolve this.
Regards,
Jack
<---code snip--->
<?
mysql_connect("localhost", "user_id", "");
$file = 'currency.txt';
$row = 1;
$fp = fopen("$file","r");
while ($data = fgets($fp,80)) {
// $iso_code = substr($data,0,3);
// switch ($iso_code); {
// case 'USD':
{
if(ereg("([0-9]{4}).([0-9]{1,2}).([0-9]){1,2})", $date_posted,
$regs)) {
echo "$regs[1]-$regs[2]-$regs[3]";
} else {
echo ($date_posted);
}
// $date_posted = '1999-06-18';
$time_posted_utc = '13:10:06';
$iso_currency_code = addslashes(substr($data,0,3));
$iso_currency = addslashes(substr($data,4,28));
$usd_units = addslashes(substr($data,35,19));
$units_usd = addslashes(substr($data,56,19));
$query = "INSERT INTO currency_rates VALUES ('$date_posted',
'$time_posted_utc', '$iso_currency_code',
'$iso_currency', '$usd_units', '$units_usd')";
}
mysql_db_query("db_name", $query);
$row++;
}
$row = ($row - 1);
echo "<p>($row) records in $file were processed.<br>\n";
fclose($fp);
?>
<---end--->