Jump to content

Split email with rules


M84

Recommended Posts

I have to split an email that is received everyday, with a set of rules. This is an example of the email:

 

A N K U N F T 11.08.15
*** NEUBUCHUNG ***
11.08.15 xxx xxx X3 2830 14:25 17:50
18.08.15 xxx xxx X3 2831 18:40
F882129 dsdsaidsaia
F882129 xxxyxyagydaysd

«CUT HERE»

A N K U N F T 18.08.15
*** NEUBUCHUNG ***
11.08.15 xxx xxx X3 2830 14:25 17:50
18.08.15 xxx xxx X3 2831 18:40
F881554 ZXCXZCXCXZCCXZ
F881554 xcvcxvcxvcvxc
F881554 xvcxvcxcvxxvccvxxcv

«CUT HERE»

11.08.15 xxx xxx X3 2830 14:25 17:50
18.08.15 xxx xxx X3 2831 18:40
F881605 xczxcdfsfdsdfs
F881605 zxccxzxzdffdsfds

«CUT HERE»


So it basically has to be cut whenever the last F999999 appears ( where 9 can be any number).

I tried the solution on a regex101.com - https://regex101.com/r/rT0yQ1/1 and it worked, however when I do this on my server with php and sending the email text by post is doesnt. I paste the email text to a textbox and then press a button that then divides it.

Here is my code: file teste.php:

 

<form method="post" action="teste2.php" enctype="multipart/form-data">
<textarea name="email" cols="110" rows="30" id="email"></textarea>
<br />
<input type="submit" value="Dividir" />
</form>

file teste2.php

 

<?php
$str = $_POST['email'];
$re = "/(?:\sF\d+.*?\n\n)(\n)/";
$subst = ">>CUT HERE>>";
$result = preg_replace($re, $subst, $str);
echo $result;
?>

I try this here: https://3v4l.org/mqrJc2 and it works. It seems like a problem when I send the text in a textarea by post the newlines disappear, because when I use a string it works. Can anyone help me?

Thank you very much in advance!

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

I try this here: https://3v4l.org/mqrJc2 and it works. It seems like a problem when I send the text in a textarea by post the newlines disappear, because when I use a string it works. Can anyone help me?

Thank you very much in advance!

 

 

Try this below.

 

$str = nl2br($_POST['email']);

$re = "/(?:\sF\d+.*?\n\n)(\n)/";
$subst = ">>CUT HERE>>";
$result = preg_replace($re, $subst, $str);
echo $result;
 
Link to comment
Share on other sites

Guest
This topic is now 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.