Jump to content

mangy1983

Members
  • Posts

    23
  • Joined

  • Last visited

    Never

Everything posted by mangy1983

  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); ?>
  16. Thank you for your reply Pikachu2000. Out of all the codes l have tried this was the best one as it reads the last email and echoes it out. as well as the unformatted (I think) body. As far as l can tell the attachments extension is .ZRXPSEND. <?php $mailbox = imap_open("{mail.******.co.uk:143/notls}INBOX", "creedlevel@*********.co.uk", "insertpasshere"); //connects to mailbox on your server if ($mailbox == false) { echo "<p>Error: Can't open mailbox!</p>"; echo imap_last_error(); } else { //Check number of messages $num = imap_num_msg($mailbox); //if there is a message in your inbox if( $num > 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 $email = imap_fetchheader($mailbox, $num); //get email header $lines = explode("\n", $email); // data we are looking for $from = ""; $subject = ""; $to = ""; $splittingheaders = true; for ($i=0; $i < count($lines); $i++) { if ($splittingheaders) { // this is a header $headers .= $lines[$i]."\n"; // look out for special headers if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) { $subject = $matches[1]; } if (preg_match("/^From: (.*)/", $lines[$i], $matches)) { $from = $matches[1]; } if (preg_match("/^To: (.*)/", $lines[$i], $matches)) { $to = $matches[1]; } } } //We can just display the relevant information in our browser, like below or write some method, that will put that information in a database echo "FROM: ".$from."<br>"; echo "TO: ".$to."<br>"; echo "SUBJECT: ".$subject."<br>"; echo "BODY: ".imap_qprint(imap_body($mailbox, $num)); imap_expunge($mailbox); } else { echo "No more messages"; } imap_close($mailbox); } ?> Below is an example of the attachment l would be sent: ## 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 They are the dates, times and water levels of a river I would like to display on a fishing website l am developing. I think that l would only want one of them or if possible the average of all of them but since l can't even code the attachments retrieval l think this would be impossible for me without at least some help. My best way of learning is to look at working code, running it and then studying it to learn how it works but since l can't even find a suitable code l am finding it very difficult. many thanks Callum
  17. I have spent nearly all day scouring Google for help on this and after trying numerous scripts unsuccessfully and reading up on imap functions but still getting nowhere as well as frying my brain l have had to accept defeat unless anyone of the many gifted coders here can help me out with a script they might have written and used. many thanks Callum
  18. Thank you so much for the code jcbones. It helped me immensely and hopefully others looking for something similar too thanks again Callum
  19. I managed to add incremental variables to the values supplied in the code supplied by jcbones (thanks again) and echo them separately outside of the loop in order to insert them into my database so here is the complete code with my own additions. Theoretically this topic is solved unless anyone thinks of a more efficient way of producing my inserted code shown below thanks again guys Callum <?php $doc = new DOMDocument(); @$doc->loadHTMLFile('http://www.metoffice.gov.uk/weather/uk/he/stornoway_forecast_weather.html'); //load the file; $desired_rows = 1; //How many rows you want from the table. $table = $doc->getElementsByTagName('table'); //get our tables out, it should return 2 from the file, we only want the second. $rows = $table->item(1)->getElementsByTagName('tr'); //pull the table rows from the second table (notice we select the second by item(1).) $count = $rows->length; //returns a count of the table rows. for($i=2,$start=$i;$i<($start + $desired_rows);$i++) { //for loop, goes through the rows. $columns = $rows->item($i)->getElementsByTagName('td'); //get columns for this row. $columnCount = $columns->length; for($n=0;$n<$columnCount;$n++) { //go through the columns. if($n == 2) { $img = $columns->item($n)->getElementsByTagName('img'); //the 3rd column is an image, so we must get the image title. $value = $img->item(0)->getAttribute('title'); } else { $value = $columns->item($n)->nodeValue; //else we will just take what is in the column. } ${a.$n} = $value; } } $patterns[0] = '/[^0-9]/'; $replacements[0] = ''; ksort($patterns); ksort($replacements); $a3 = preg_replace($patterns, $replacements, $a3); $a5 = preg_replace($patterns, $replacements, $a5); $a6 = preg_replace($patterns, $replacements, $a6); echo $a0, '</br>', $a1, '</br>', $a2, '</br>', $a3, '</br>', $a4, '</br>', $a5, '</br>', $a6, '</br>', $a7, '</br>', $a8; ?>
  20. thank you soo much for the work you did on this it is well appreciated! As my previous post l was wondering if it is possible to have each td tags element saved as a variable in order to save them to a database. I would then run this script every 3 hours using a cron job to update the database table. If yourself or one of the other great members on here can be of help l would be immensely grateful. Once the td elements have been turned into variables l will be on familiar territory to save the information to the database. thanks again Callum
  21. Thanks for your reply. Unfortunately I don't know how to use curl l am afraid and it doesn't make much sense to me at the moment. I use codes from examples at the moment and once l get them working I learn what each line does so as to understand what everything does. The code from the example I gave in my first post l can understand bits of it and like the way that you can turn the tds elements information into separate variables to use as you wish later. thanks again Callum
  22. I have done it this way before when trying to get a single element which l did not have too much of a problem with. The problem with the code l need to grab is that it is inside a nameless table, and that the td's all have the same class name. There are also several instances of these class names in different rows as the weather is displayed for every three hours on a separate row whereas l only need a few of the tds from the first row. For instance l would like to have a screen grab of the first row in the weather table at this weblink http://www.metoffice.gov.uk/weather/uk/he/stornoway_forecast_weather.html Hope this makes sense. thanks Callum
  23. Hi all I am developing a website for a fishing organisation which was to include a weather widget. The only weather widget which blended into the colours of the website l am creating was the second transparent widget on this web page http://www.weatherforecastmap.com/getwidget.phtml/ . It has been fine for the last month apart from it is not as accurate as a local website. On top of this members are complaining that wind speeds are measured in m/s instead of mph which is the UK measurement. I have been scouring the net for a screen scraping code which will scrape the information I want from the local website and found the code supplied on this webpage: http://www.bradino.com/php/screen-scraping/ This looks to do what l want as the website l want displays the weather in a table displaying the weather at 3 hour intervals per row. I would only like to extract the information from the first row but the code in the link does not work for me. If anyone could help me with this it would be great! Below is the code l have as l wanted to get the example working before l customised it to my own use. thanks for any replies Callum <?php $url = "http://www.nfl.com/teams/sandiegochargers/roster?team=SD"; $raw = file_get_contents($url); $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B"); $content = str_replace($newlines, "", html_entity_decode($raw)); $start = strpos($content,' $end = strpos($content,' ',$start) + 8; $table = substr($content,$start,$end-$start); preg_match_all("| |U",$table,$rows); foreach ($rows[0] as $row){ if ((strpos($row,' preg_match_all("| |U",$row,$cells); $number = strip_tags($cells[0][0]); $name = strip_tags($cells[0][1]); $position = strip_tags($cells[0][2]); echo "{$position} – {$name} – Number {$number} \n"; } } ?>
×
×
  • 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.