M84 Posted August 20, 2015 Share Posted August 20, 2015 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:5018.08.15 xxx xxx X3 2831 18:40F882129 dsdsaidsaiaF882129 xxxyxyagydaysd «CUT HERE» A N K U N F T 18.08.15*** NEUBUCHUNG ***11.08.15 xxx xxx X3 2830 14:25 17:5018.08.15 xxx xxx X3 2831 18:40F881554 ZXCXZCXCXZCCXZF881554 xcvcxvcxvcvxcF881554 xvcxvcxcvxxvccvxxcv «CUT HERE» 11.08.15 xxx xxx X3 2830 14:25 17:5018.08.15 xxx xxx X3 2831 18:40F881605 xczxcdfsfdsdfsF881605 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 More sharing options...
hansford Posted September 16, 2015 Share Posted September 16, 2015 You can try this for now: $re = "/(\sF\d+.*[\r\n]{3,})/"; Link to comment Share on other sites More sharing options...
valandor Posted October 13, 2015 Share Posted October 13, 2015 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; nl2br() Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 16, 2015 Share Posted October 16, 2015 Topic locked. Due to attracting a lot of spammers. @M84 if you want to reply PM me or click the Report link and a moderator/admin will unlock for you. Link to comment Share on other sites More sharing options...
Recommended Posts