Jump to content

how to strip everything between key phrase and ending tag


Anandlall12

Recommended Posts

Hey guys. I am trying to strip everything between a key phrase and ending tag but for some reason it is not working. I always get blank data. I've tried many different ways but no luck.

 

basically I have a script that connect to imap and store emails into MySQL as service tickets. works great but I am trying to strip everything except for user reply because currently if a user reply to an email it re-inserts the entire email into MySQL. I added a key phrase at the top of all outgoing emails .

 

1. structure looks like this.

 

--Reply below this line to respond--

------------------------------------------------------------------------------------------------

 

Email body message...

 

2. When replying to the message it becomes

 

New Message reply......

 

--Reply below this line to respond--

 

old message body.

 

 

3. so I would only like to insert the new reply message only.

 

 

This is what I got so far.

 

    $message=strip_tags($message, "<br><div><p><u><hr></section>");

 

    $message=preg_replace("</p>", "br /", $message);
   
    $message=preg_replace('#--REPLY above this line to respond--(.*?)</section>)#s', ' ', $message);
   
    $message=clean("<br/><hr><u>Received On $rep_date / $from_email</u><br><br/>$message");

 

 

it inserts the "Received On date and From but $message is blank.

 

If i remove $message=preg_replace('#--REPLY above this line to respond--(.*?)</section>)#s', ' ', $message);  it inserts the entire email

 

Any suggestion on what i am doing wrong?

 

thank you all very much.

 

Try preg_match 

$message =strip_tags($message, "<br><div><p><u><hr></section>");
$message =preg_replace("</p>", "br /", $message);
$message = preg_match('~(.*?)(?:--Reply below this line to respond--)~is', $message, $m);
$message =clean("<br/><hr><u>Received On $rep_date / $from_email</u><br><br/>{$m[0]}");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.