Jump to content

Any good at PHP coding Language2?


Recommended Posts

I hate to ask but after having 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 :cry: 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 or use. :thumbs:

 

many thanks Callum

Link to post
Share on other sites

get CodeGear's Delphi PHP will solve everything :thumbs: if you cant find it let me no i might upload mine if i have time

 

Thanks mate will have a look for it. I love php when it goes right and you know what you are doing but since the amount of options and functions etc are nearly finite it is very frustrating when you don't have a clue what you are doing...

 

thanks Callum

Link to post
Share on other sites

What are you trying to achieve?

php is simple if you can explain in english what you want the end result to be!

 

When coding a new script, you need to write a readable progress sheet wich lists all conditions which will be read or checked.

 

Give us some clue as to what you are trying to achieve and maybe someone can help you!

Link to post
Share on other sites

What are you trying to achieve?

php is simple if you can explain in english what you want the end result to be!

 

When coding a new script, you need to write a readable progress sheet wich lists all conditions which will be read or checked.

 

Give us some clue as to what you are trying to achieve and maybe someone can help you!

 

Ok mate l am developing a website for a local angling club and l have been in touch with SEPA who will send me an automated email 3 times a day of the current water levels of a river they run which if l can get a script to echo out the attachments readings l will then run it about the same times that the emails are sent using a cron job.

 

Below is the code l got off the net the day (the best one out of all the ones l tried) and below that is the example attachment l was sent by SEPA.

 

<?php
$mailbox = imap_open("{mail.syaa.co.uk:143/notls}INBOX", "creedlevel@syaa.co.uk", "Cr33dL3v31");  //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);
}
?>

 

## 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 the river I would like to display. 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. 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

Link to post
Share on other sites

From what i can gather, you want to find the average number from those results right?

 

You need to put those values into an array then find the highest and lowest within that array then find the average to echo out to your page.

 

To get an idea of what you should be looking at, take a look here: http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/

 

This will give you an example of a working script, you just need to adapt what you have to work alongside.

 

I have never needed to read email attachments before so not familiar with it, but i cannot imagine that it is that awkward to work out.

Link to post
Share on other sites

From what i can gather, you want to find the average number from those results right?

 

You need to put those values into an array then find the highest and lowest within that array then find the average to echo out to your page.

 

To get an idea of what you should be looking at, take a look here: http://www.mdj.us/we...array-with-php/

 

This will give you an example of a working script, you just need to adapt what you have to work alongside.

 

I have never needed to read email attachments before so not familiar with it, but i cannot imagine that it is that awkward to work out.

 

Neither had l mate, till this problem came up. I would have screen scraped the info from their website which they don't mind but the data is calculated and output in a flaming png image so my options were either an image reader or they send me emails and l read the attachments. The script above was ready to work if the data was directly in the email itself (as I hoped) as l could have just used regex to filter out the unneeded data plus l thought it would be just one result per email. Then l was planning to save it in my own database and output it on the website in a similar graph, :hmm:

Link to post
Share on other sites

I know the feeling, i looked at a weather widget a few years ago, and the same thing was happening!

I think they put the info into a image so they dont get thousands of hits from servers wanting the info, thus using thier bandwidith wich is fair enough.

If you can capture the data like you present, just bung it into an array and sort it that way, or even better, get them to present it to you in xml format.

Link to post
Share on other sites

I know the feeling, i looked at a weather widget a few years ago, and the same thing was happening!

I think they put the info into a image so they dont get thousands of hits from servers wanting the info, thus using thier bandwidith wich is fair enough.

If you can capture the data like you present, just bung it into an array and sort it that way, or even better, get them to present it to you in xml format.

 

My previous php topic might be of help to you in that regard. I had the data saved to my own database instead of screen scraping the weather forecasts website every time the page was loaded up and l must say l loved the end result. You can view it here http://www.syaa.co.uk/Fishing_Location/index.php?Location=The_River_Creed

 

cheers Callum

Link to post
Share on other sites

I managed to get a code and modify it a wee bit from the bits l understood to echo out the attachment. I'm guessing l have to use preg replace to filter the info l need. I know how to filter letters out but never done letters + certain numbers and throw the rest into an array.

 

Hmmm :hmm: fix one problem and the next one comes along. :sorry:

 

Any tips.

 

thanks Callum

 

Here my code so far for anyone interested:

 

<?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);


?>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...