Jump to content

mangy1983

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mangy1983's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks again mjdamato. Your information once again was invaluable. cheers Callum
  2. sorry guys l figured it out. It was just the fact that l was echoing out the variables whilst the variable providing the information was still in a loop. I used the end array instead of what l was trying to do. I was aware of the array data starting at 0 and that l would have to subtract one form it but the problem was that 2 array 0's were being echoed out which was causing the weird results. I changed this line: $attachment = $attachments[$i]['attachment']; by removing the $i and hard coding the number 1 in its place as the original code l used before modifying it to my own use loaded up all emails and then loaded up all attachments whereas l only wanted the last emails attachment loaded up. thanks Callum
  3. I don't know if this is the correct section of the forum to implement this code but l thought since a lot of the guys here helped me with this code l should share my completed code faulty or not (it works for me!) in the hope it helps someone else. It will read an attachment from the last email received to the specified account and remove all data bar data with a numerical decimal value and echo it out. I have spent 3 days trawling the internet and getting help with this code as well as learning from it so l would just like to thank everybody who helped me create it in one way or another. cheers Callum <?php $mbox = imap_open("{mail.*****.co.uk:143/notls}INBOX", "****@****.co.uk", "*****"); //connects to mailbox on your server $headers = imap_headers($mbox); if ($headers == false) { print_r(imap_errors()); } else { $j = imap_num_msg($mbox); //if there is a message in your inbox if( $j > 0 ) { //this just reads the most recent email. In order to go through all the emails, you'll have to loop through the number of messages $info = imap_headerinfo($mbox,$j); $structure = imap_fetchstructure($mbox, $info->Msgno); $attachments = array(); if (isset($structure->parts) && count($structure->parts)) { for ($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody( $mbox, $info->Msgno, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } $attachment = $attachments[1]['attachment']; preg_match_all("#\d+\.\d+#", $attachment, $matches); } } $riverlevel = end($matches[0]); } } } imap_close($mbox); echo $riverlevel; ?>
  4. I know what is wrong now but cant fathom what is causing my problem. There are numerous loops. When $matches is print_r'd in its current loop it shows the first array 0 (the correct one) and the second array 0 but when l move it to any of the other loops it only displays the second array 0. Any ideas guys. If anyone wants to have a go l can give them the correct details for the censored out areas at the top of the by pm thanks Callum Below is my whole code bar my personal details: <?php $mbox = imap_open("{mail.*****.co.uk:143/notls}INBOX", "creedlevel@****.co.uk", "******"); //connects to mailbox on your server $headers = imap_headers($mbox); if ($headers == false) { print_r(imap_errors()); } else { $j = imap_num_msg($mbox); //if there is a message in your inbox if( $j > 0 ) { //this just reads the most recent email. In order to go through all the emails, you'll have to loop through the number of messages $info = imap_headerinfo($mbox,$j); $structure = imap_fetchstructure($mbox, $info->Msgno); $attachments = array(); if (isset($structure->parts) && count($structure->parts)) { for ($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody( $mbox, $info->Msgno, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } $attachment = $attachments[$i]['attachment']; preg_match_all("#\d+\.\d+#", $attachment, $matches); print_r ($matches); } } } } } imap_close($mbox); ?>
  5. I honestly don't know unless it is something to do with the fact that for some reason l think l have two 0 arrays. I have removed the middle rows of the array l posted to save space as they are pretty much the same information. cheers Callum
  6. Kindoff works mate but it is displaying two bits of information. I copied pasted the array again this time in code tags as l noted that when l didn't the 0' were removed. Its kind off weird but l think there are 2 array 0's thanks Callum Array ( [0] => Array ( [0] => 2206.235 [1] => 3.9 [2] => 0.48 [3] => 0.477 [4] => 0.477 [5] => 0.475 [215] => 0.434 [216] => 0.436 [217] => 0.435 [218] => 0.434 [219] => 0.435 [220] => 0.435 ) ) Array ( [0] => Array ( [0] => 2206.235 [1] => 3.9 [2] => 0.48 [3] => 0.48 [4] => 0.435 [5] => 0.435 ) )
  7. I have an array that displays the following information with the print_r function: Array ( [0] => Array ( [0] => 2206.235 [1] => 3.9 [2] => 0.48 [3] => 0.477 [4] => 0.477 [5] => 0.475 [215] => 0.434 [216] => 0.436 [217] => 0.435 [218] => 0.434 [219] => 0.435 [220] => 0.435 ) ) Array ( [0] => Array ( [0] => 2206.235 [1] => 3.9 [2] => 0.48 [3] => 0.48 [4] => 0.435 [5] => 0.435 ) ) I would like to save the last row to my database which in this case is 220 but the last row could vary from time to time as the array is created from an email attachment so l wanted a code that would find the number of rows in the array. When l echo out the row like this: echo $matches[0][210] it retrieves the correct information so l wanted to implement this code instead to cater for an unknown amount of array rows so that the highest row was always returned: $i = count($matches[0]); echo $matches[0][$i]; but this does not work as when echoing $i the result is 2216 instead of 220 which l find odd or l am doing something wrong. Any ideas? thanks Callum
  8. I had help from the good guys on this forum myself with a similar problem. What you want to do is called screen scraping. I'm only posting some advice which l found out the hard way. I would have the data saved to a database as the way you you want it coded it will screen scrape from the http://www.kitco.com/texten/texten.html every time the page is loaded. This not only slows your page from loading whilst it retrieves the information but if the kitcos server admin sees all of your servers access to their server for the information you want to display they could block you especially if you have 100's of people loading up your page regularly. You could run your script once a day/hour etc using a cron job and save required data to your database. just my two cents worth cheers Callum
  9. I'm nearly there now. I just need to know how l can automatically have it display the highest number of the second column (last row) inside the array as with the code l have used (thanks again mjdamato) l have found that the array row containing the data l require is in array row $matches[0][220]. I am just future proofing the script as l am guessing that l will be sent variable amounts of rows in the attachments so having a set row number ie 220 in this case will not always work. thanks Callum
  10. edited to say l figured my problem out with your code and l must say you sir are a genius! cheers Callum
  11. I am just looking to strip the last decimal number (the latest) in order to save it to a database and therefore display the value on my website. thank you for your help cheers Callum
  12. Yes that is exactly the values l am trying to get. I am looking to strip these values and add them into an array so that the last of the values (the latest) can be added to a database and from there displayed on my website thanks yo for your reply cheers Callum
  13. I have a variable that when echoed out displays the information from an email attachment (see below). My problem is although l know l should use preg replace l have absolutely no idea were to begin with this. I am looking for a snippet of code that will remove all information bar the decimal numbers. I have managed to remove all alphanumeric characters with preg replace but thats as far as l understand it. can anyone help me please? thanks Callum Below is the original attachment which consists of date and time in YYYYMMDDHHmmss format and the last 3 or four decimal numbers are of a rivers water level ## Exported ZRXP Block for Halkirk.SG.ir.O ##TSNAMEHalkirk.SG.ir.O;*; #ZRXPVERSION2206.235;*;ZRXPCREATORZEXP3.9.2;*; #ZRXPMODEextended;*; #CUNITm;*; #SNAMEHalkirk;*;SANR234231;*;SWATERThurso;*;CNR3033705;*; #CNAMESG;*;CMW86400;*;CTYPEn-min-ip;*; #RTYPEMomentanwerte;*;RTIMELVLHochaufloesend;*;RORPRoriginal;*;CNTYPE1;*; ##DAYSTART0000 #REXCHANGEHalkirk.SG.ir.O;*; #RSTATEW6;*; 20080224000000 0.48 0 20080224001500 0.477 0 20080224003000 0.477 0 20080224004500 0.475 0 20080224010000 0.477 0 20080224011500 0.475 0 20080224013000 0.476 0 20080224014500 0.473 0 20080224020000 0.471 0 20080224021500 0.469 0 20080224023000 0.469 0 20080224024500 0.466 0 20080224030000 0.466 0 20080224031500 0.464 0 20080224033000 0.463 0 20080224034500 0.461 0 20080224040000 0.458 0 20080224041500 0.458 0 20080224043000 0.456 0 20080224044500 0.456 0 20080224050000 0.457 0 20080224051500 0.454 0 20080224053000 0.455 0 20080224054500 0.452 0 20080224060000 0.452 0 20080224061500 0.452 0 20080224063000 0.451 0 20080224064500 0.452 0 20080224070000 0.451 0 20080224071500 0.451 0 20080224073000 0.449 0 20080224074500 0.451 0 20080224080000 0.448 0 20080224081500 0.447 0 20080224083000 0.449 0 20080224084500 0.448 0 20080224090000 0.448 0 20080224091500 0.445 0 20080224093000 0.444 0 20080224094500 0.446 0 20080224100000 0.448 0 20080224101500 0.448 0 20080224103000 0.449 0 20080224104500 0.45 0 20080224110000 0.448 0 20080224111500 0.448 0 20080224113000 0.449 0 20080224114500 0.449 0 20080224120000 0.451 0 20080224121500 0.449 0 20080224123000 0.45 0 20080224124500 0.449 0 20080224130000 0.45 0 20080224131500 0.448 0 20080224133000 0.452 0 20080224134500 0.452 0 20080224140000 0.454 0 20080224141500 0.456 0 20080224143000 0.455 0 20080224144500 0.459 0 20080224150000 0.457 0 20080224151500 0.456 0 20080224153000 0.454 0 20080224154500 0.457 0 20080224160000 0.457 0 20080224161500 0.458 0 20080224163000 0.461 0 20080224164500 0.458 0 20080224170000 0.458 0 20080224171500 0.46 0 20080224173000 0.46 0 20080224174500 0.458 0 20080224180000 0.462 0 20080224181500 0.462 0 20080224183000 0.459 0 20080224184500 0.461 0 20080224190000 0.459 0 20080224191500 0.456 0 20080224193000 0.453 0 20080224194500 0.448 0 20080224200000 0.446 0 20080224201500 0.443 0 20080224203000 0.44 0 20080224204500 0.439 0 20080224210000 0.431 0 20080224211500 0.428 0 20080224213000 0.423 0 20080224214500 0.42 0 20080224220000 0.416 0 20080224221500 0.414 0 20080224223000 0.41 0 20080224224500 0.407 0 20080224230000 0.406 0 20080224231500 0.403 0 20080224233000 0.401 0 20080224234500 0.399 0 20080225000000 0.397 0 20080225001500 0.394 0 20080225003000 0.393 0 20080225004500 0.392 0 20080225010000 0.391 0 20080225011500 0.39 0 20080225013000 0.389 0 20080225014500 0.389 0 20080225020000 0.388 0 20080225021500 0.388 0 20080225023000 0.39 0 20080225024500 0.39 0 20080225030000 0.39 0 20080225031500 0.389 0 20080225033000 0.391 0 20080225034500 0.391 0 20080225040000 0.39 0 20080225041500 0.39 0 20080225043000 0.39 0 20080225044500 0.39 0 20080225050000 0.39 0 20080225051500 0.388 0 20080225053000 0.388 0 20080225054500 0.388 0 20080225060000 0.388 0 20080225061500 0.389 0 20080225063000 0.388 0 20080225064500 0.387 0 20080225070000 0.387 0 20080225071500 0.387 0 20080225073000 0.387 0 20080225074500 0.386 0 20080225080000 0.387 0 20080225081500 0.386 0 20080225083000 0.386 0 20080225084500 0.386 0 20080225090000 0.386 0 20080225091500 0.384 0 20080225093000 0.386 0 20080225094500 0.386 0 20080225100000 0.386 0 20080225101500 0.386 0 20080225103000 0.388 0 20080225104500 0.387 0 20080225110000 0.387 0 20080225111500 0.387 0 20080225113000 0.387 0 20080225114500 0.387 0 20080225120000 0.387 0 20080225121500 0.386 0 20080225123000 0.386 0 20080225124500 0.387 0 20080225130000 0.383 0 20080225131500 0.383 0 20080225133000 0.383 0 20080225134500 0.383 0 20080225140000 0.382 0 20080225141500 0.382 0 20080225143000 0.382 0 20080225144500 0.383 0 20080225150000 0.382 0 20080225151500 0.382 0 20080225153000 0.379 0 20080225154500 0.38 0 20080225160000 0.379 0 20080225161500 0.38 0 20080225163000 0.379 0 20080225164500 0.378 0 20080225170000 0.383 0 20080225171500 0.379 0 20080225173000 0.383 0 20080225174500 0.382 0 20080225180000 0.382 0 20080225181500 0.382 0 20080225183000 0.382 0 20080225184500 0.382 0 20080225190000 0.382 0 20080225191500 0.38 0 20080225193000 0.383 0 20080225194500 0.382 0 20080225200000 0.383 0 20080225201500 0.383 0 20080225203000 0.384 0 20080225204500 0.386 0 20080225210000 0.391 0 20080225211500 0.395 0 20080225213000 0.398 0 20080225214500 0.406 0 20080225220000 0.412 0 20080225221500 0.418 0 20080225223000 0.426 0 20080225224500 0.43 0 20080225230000 0.432 0 20080225231500 0.432 0 20080225233000 0.436 0 20080225234500 0.439 0 20080226000000 0.44 0 20080226001500 0.44 0 20080226003000 0.443 0 20080226004500 0.441 0 20080226010000 0.443 0 20080226011500 0.443 0 20080226013000 0.444 0 20080226014500 0.443 0 20080226020000 0.442 0 20080226021500 0.443 0 20080226023000 0.443 0 20080226024500 0.44 0 20080226030000 0.442 0 20080226031500 0.44 0 20080226033000 0.44 0 20080226034500 0.436 0 20080226040000 0.437 0 20080226041500 0.435 0 20080226043000 0.436 0 20080226044500 0.436 0 20080226050000 0.432 0 20080226051500 0.434 0 20080226053000 0.436 0 20080226054500 0.435 0 20080226060000 0.434 0 20080226061500 0.435 0 20080226063000 0.435 0 the beginning of the echoed information and the end of the echoed information
  14. I believe this topic to be solved as the last code l posted pretty much does as stated in the topic title so l am going to tag it as solved. thanks all who helped. cheers Callum
  15. After further investigating and experimenting l have now got a code that echoes out the attachment but l am not sure how to proceed with it as l am not sure what l am doing. Out of all the information held l am only looking at keeping the 0.477 type of digits in the attachments so that l can find the average of them and display the output as well as saving it to database. Would anyone be able to help with this? thanks Callum Heres my code so far: <?php $mbox = imap_open("{mail.*******.co.uk:143/notls}INBOX", "creedlevel@*********.co.uk", "*********"); //connects to mailbox on your server $headers = imap_headers($mbox); if ($headers == false) { print_r(imap_errors()); } else { $j = imap_num_msg($mbox); //if there is a message in your inbox if( $j > 0 ) { //this just reads the most recent email. In order to go through all the emails, you'll have to loop through the number of messages $info = imap_headerinfo($mbox,$j); $structure = imap_fetchstructure($mbox, $info->Msgno); $attachments = array(); if (isset($structure->parts) && count($structure->parts)) { for ($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { if(strtolower($object->attribute) == 'filename') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { if(strtolower($object->attribute) == 'name') { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody( $mbox, $info->Msgno, $i+1); if($structure->parts[$i]->encoding == 3) { // 3 = BASE64 $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } elseif($structure->parts[$i]->encoding == 4) { // 4 = QUOTED-PRINTABLE $attachments[$i]['attachment'] = quoted_printable_decode($attachments[$i]['attachment']); } echo "<br>" . $attachments[$i]['attachment']; echo $attachments[1]; } } } } } imap_close($mbox); ?>
×
×
  • 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.