Skinzy Posted March 16, 2010 Share Posted March 16, 2010 Hi, Basically I have a big peice of text in my php script (i'm parsing email, i've got rid of the MIME stuff) and now i'm trying to remove a fixed signiture that's not going to change. The str_replace fails because (i think) the string is too long, if i take a small section of the string and for example change $goaway to "The contents of this email are" it works and removes that bit of text from the variable. But when I do the whole lot it doesn't do anything. Is there another method like str_replace to get rid of a big chunk of text? <?php require_once('MimeMailParser.class.php'); $path = 'email.eml'; $Parser = new MimeMailParser(); $Parser->setPath($path); $to = $Parser->getHeader('to'); $from = $Parser->getHeader('from'); $subject = $Parser->getHeader('subject'); $text = $Parser->getMessageBody('text'); $html = $Parser->getMessageBody('html'); $attachments = $Parser->getAttachments(); $save_dir = '/home/freelance/domains/freelance.skinzy.net/public_html/uploads/'; foreach($attachments as $attachment) { $filename = $attachment->filename; if ($fp = fopen($save_dir.$filename, 'w')) { while($bytes = $attachment->read()) { fwrite($fp, $bytes); } fclose($fp); } } $goaway = "=20 =20 -------------------------------------------------------------------------= ------- The contents of this email are confidential and are only intended for = the stated recipient. The email is the property of Direct Enquiries = Limited and if you are not the stated recipient you must not deal with = it in any way other than to notify us of its receipt by you in error. = This email is not intended nor should it be taken to create any legal = relations, contractual or otherwise. Any views or opinions expressed in = this email or attachment are solely those of the sender and do not = necessarily represent those of Direct Enquiries Limited unless otherwise = specifically stated. Although all outgoing emails have been checked for viruses, we do not = accept liability for any damage you sustain as a result of a virus = contained within an email originating from us. All outgoing and = incoming emails to and from Direct Enquiries Limited are monitored in = accordance with the Lawful Business Practice Regulations and senders of = messages shall be taken to consent to the monitoring and recording of = emails addressed to our employees.=20 Direct Enquiries Limited is a company registered in England with company = number 4519178. Registered Office: Amber House, Market Street, Bracknell, Berkshire, = RG12 1JB -------------------------------------------------------------------------= -------"; $clear = " "; $please = str_replace($goaway, $clear, $text); echo "Subject: " . $subject . "<br /> Text:" . $please; ?> really appreciate it. Tom Link to comment https://forums.phpfreaks.com/topic/195452-delete-a-big-string-of-text/ Share on other sites More sharing options...
nafetski Posted March 16, 2010 Share Posted March 16, 2010 Hrmn, I wasn't aware that str_replace had any limits on it. There is another PHP function you can use. preg_replace()...and I know for a fact it has no limit Link to comment https://forums.phpfreaks.com/topic/195452-delete-a-big-string-of-text/#findComment-1027048 Share on other sites More sharing options...
Skinzy Posted March 16, 2010 Author Share Posted March 16, 2010 It might not have a limit on it, but somthing is stopping it working. Can I use preg_replace the same way as str_replace? Link to comment https://forums.phpfreaks.com/topic/195452-delete-a-big-string-of-text/#findComment-1027052 Share on other sites More sharing options...
fr34k Posted March 16, 2010 Share Posted March 16, 2010 Hi, Basically I have a big peice of text in my php script (i'm parsing email, i've got rid of the MIME stuff) and now i'm trying to remove a fixed signiture that's not going to change. The str_replace fails because (i think) the string is too long, if i take a small section of the string and for example change $goaway to "The contents of this email are" it works and removes that bit of text from the variable. But when I do the whole lot it doesn't do anything. Is there another method like str_replace to get rid of a big chunk of text? really appreciate it. Tom Are you sure that there are no new line/carriage returns in the text you're trying to replace? If you're omitting line breaks or trailing spaces, it will won't match the text and won't replace it. You don't need a variable for your replace, either. You can simply use something like: str_replace($goaway, null, $text) or str_replace($goaway, '', $text) Link to comment https://forums.phpfreaks.com/topic/195452-delete-a-big-string-of-text/#findComment-1027062 Share on other sites More sharing options...
Skinzy Posted March 16, 2010 Author Share Posted March 16, 2010 After a bit of googling i've now sorted it with: $pos = strpos($text, "-------------------------------------------------------------------------="); $please = substr($text, 0, $pos); $text2 = str_replace($up, "<br /> <br />", $please); thanks for your help Link to comment https://forums.phpfreaks.com/topic/195452-delete-a-big-string-of-text/#findComment-1027067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.