I am having a hard time with a script that will truncate junk returned in an email. Here are two examples...

Yup, lets see... Dan ----- Original Message ----- From: To: " Dan" Sent: Wednesday, February 09, 2005 10:09 PM Subject: RE:Test: Case Number: 3 > > > Greetings, > > > Email test for new address. > > > > Somegarbage >

I would like to remove everything from ----- Original Message ----- and after.

Second Example....

This is a multi-part message in MIME format. ------=NextPart_001_01C50F1C.540CE3C2 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Retesting Reply with correct address somemore junk

I would like to strip everything before and after "Retesting Reply with correct address" which was the actual reply.

I've beat to death preg_replace, str_replace but can't get it to work right. Help appreciated.

Rab

    OK first you need to get the string. In this case

    "--------- Original Message -------------"

    Next you need to find the first occurence of the string using the following function:

    strpos($fullmessage, $needle);

    where $fullmessage is the email text and $needle is the original message string.

    this function returns the offset as an integer.

    Ok then we need strip out everything from $needle onwards like you wanted

    So we use:
    substr($fullmessage, $start, $offset);

    where $fullmessage is the email text, $start should be 0 and the $offset we get from strpos(); but in this case we remove 1 from the $offset. So $offset should be $offset - 1. The reason for this is to remove the first character of "----------- Original Message -----------".

    I hope this is what you where looking for

      Write a Reply...