Ross Hulford wrote:
Her is the code (not mine) what I am trying to so is cut out all the
header
info that is included in the message as shown here
http://supercool-74.com/sms/liveticker.php
Granted, it's 5 hours later, but I'm not seeing anything much at that URL...
The message is supposed to be terminated by the xx string which is
defined
in config.php but it just continues and prints all the header info too.
I'm confused by your placement of header info and rest of message...
Since the headers come FIRST, I don't quite understand why you are having
problems with it printing headers info *after* the content...
So I'll comment on the parts of code that I *do* understand, and maybe
push you in the right direction for something anyway.
-
?php
include (config.php);
$mbox = imap_open ({.$pop3_server./pop3:110}INBOX,$mailbox,$password);
You are usually better off using IMAP instead of POP when possible.
$headers = imap_headers ($mbox);
$max = count($headers);
include (head.php);
echo table border=\0\ cellspacing=\30\ cellpadding=\0\\n;
for ($i = $max; $i 0; $i--)
{
$header = imap_header ($mbox,$i);
$from = $header-from;
$email = $from[0]-mailbox.@.$from[0]-host;
Hmmm. I'm assuming this is correct, that $header-from is an array?
And that's already all torn apart into -mailbox and -host elements?
Seems to me you might be able to get this more clearly somehow from the
$header structure, but maybe that's just the way it is
$date = $header-date;
$date = split( ,$date);
Might as well use http://php.net/explode if you're not going to use the
power of RegEx.
$structure = imap_fetchstructure ($mbox,$i);
$encoding = $structure-encoding;
if ($endword)
{
$end = strpos(imap_body ($mbox,$i),$endword);
}
if ($startword)
{
$beginning = ereg($startword,imap_body ($mbox,$i));
$start = strpos(imap_body ($mbox,$i),$startword);
if ($end)
Here's your FIRST big problem that is probably actually related to what
you are asking about.
$end could *easily* have been 0 (the integer) if $endword appeared at the
very *beginning* of the imap_body($mbox, $i) expression.
Now maybe that never happens in the real world with your data, but it's
really better to use if ($end !== FALSE) here to make sure you don't get
in the Bad Habit of confusing 0 and FALSE results from strpos().
{
$body = substr(imap_body
($mbox,$i),$start+strlen($startword),$end-$start-strlen($endword));
}
else
{
$body = substr(imap_body ($mbox,$i),$start+strlen($startword));
}
}
You are calling image_body($mbox, $i) several times in here. It would
probably be better to do $body = imap_body($mbox, $i) early on, and then
just use $body.
It may be more natural, if $end === FALSE, to set $end to strlen($body) at
that point, and then just have one call to substr() to get the portion of
the $body you want.
else
{
$beginning = true;
if ($end)
{
$body = substr(imap_body ($mbox,$i),0,$end);
}
else
{
$body = imap_body ($mbox,$i);
}
}
So now I'm very confused about your beginning, end, start, body, and
substr() calls, because I have NO IDEA what you are doing at this point...
A cleaner structure, IMHO would be:
$body = imap_body($mbox, $i);
//Find the end of the section we want:
$endpos = strlen($body); //Whole thing, by default
if (strlen($endword)){
$endpos = strpos($body, $endword);
if ($endpos === FALSE) $endpos = strlen($body);
}
//Find the beginning of the section we want:
$startpos = 0; //Whole thing, by default:
if (strlen($startword)){
$startpos = strpos($body, $startword);
if ($startpos === FALSE) $startpos = 0;
else{
$startpos += strlen($startword); //Don't include $startword in result
}
}
//Now get the section defined by $startpos, $endpos:
$body = substr($body, $startpos, $endpos);
If you are *still* not getting what you think you should, use:
echo HRPREOriginal: ', imap_body($mbox, $i), '\nStart: '$startword'
$startpos\nEnd: '$endword' $endpos\nBody: '$body'/PREHR\n;
here to figure out why.
Pay close attention to what's inside the ''s in that output, such as
newlines and spaces, which are the usual things to trip you up in this
kind of work.
if (in_array ($email,$allowed_senders) $beginning)
{
if ($date[1] == 1){$date[1]=01;}
elseif ($date[1] == 2){$date[1]=02;}
elseif ($date[1] == 3){$date[1]=03;}
elseif ($date[1] == 4){$date[1]=04;}
elseif ($date[1] == 5){$date[1]=05;}
elseif ($date[1] == 6){$date[1]=06;}
elseif ($date[1] == 7){$date[1]=07;}
elseif ($date[1] == 8){$date[1]=08;}
elseif ($date[1] == 9){$date[1]=09;}
Is is just silly. Use something like:
$date_1 = sprintf('%02s', $date[1]);
if ($date[2] == Jan){$date[2]=01;}
elseif ($date[2] == Feb){$date[2]=02;}
elseif ($date[2] == Mar){$date[2]=03;}
elseif ($date[2] == Apr){$date[2]=04;}
elseif ($date[2] == May){$date[2]=05;}
elseif