ethanhayon Posted July 17, 2008 Share Posted July 17, 2008 Hi, I am using PHP to read through emails on a POP3 server. I get the emails out just fine and creates an array of the email by line, but I am trying to remove the "=" that is created when there is a new line. Here is an example of the output: PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that = i can have I have tried using this code to solve it: $text = trim($message,"="); but that has not worked. Does anybody have any ideas about how to solve this? Thanks in Advance! -Ethan Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/ Share on other sites More sharing options...
valaris Posted July 17, 2008 Share Posted July 17, 2008 Perhaps something like $text = str_replace("=", " ", $yourArray); Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592498 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Perhaps try $line = preg_replace( '/=(?:\\r|\\n)/', '', $line ) Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592500 Share on other sites More sharing options...
ethanhayon Posted July 17, 2008 Author Share Posted July 17, 2008 Perhaps something like $text = str_replace("=", " ", $yourArray); Ok, that worked fine, but what if the actual message consisted of an "=" sign that i do not want to remove. For example: PROBLEM CODE: Level 5 PROBLEM: i get a messege that says = 0x000021 that i have exceeded the number of devices that = i can have I do not want to remove the = that is in the middle of the phrase Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592523 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Refer to my post, it will only remove = followed by a linebreak character. Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592525 Share on other sites More sharing options...
ethanhayon Posted July 17, 2008 Author Share Posted July 17, 2008 Refer to my post, it will only remove = followed by a linebreak character. when i use that code, nothing happens Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592555 Share on other sites More sharing options...
The Little Guy Posted July 17, 2008 Share Posted July 17, 2008 You need to use double quotes, not single quotes: $line = preg_replace( "/=(\r|\n)/", '', $line ) Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592557 Share on other sites More sharing options...
muffinsincream Posted July 17, 2008 Share Posted July 17, 2008 Refer to my post, it will only remove = followed by a linebreak character. when i use that code, nothing happens It will only work if the = is followed by a linebreak character, so it shouldn't do anything if it isn't followed by the linebreak character. Maybe the syntax is bad. Check your error log. Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592560 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 Refer to my post, it will only remove = followed by a linebreak character. when i use that code, nothing happens Then you're giving us bad sample data. It works fine for me. See bottom of post. You need to use double quotes, not single quotes: $line = preg_replace( "/=(\r|\n)/", '', $line ) No, I don't See below <?php $data = <<<SAMPLE PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that = i can have SAMPLE; $data = preg_replace( '/=(?:\\r|\\n)/', '', $data ); echo $data; ?> Outputs PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that i can have Which is wrong anyways... here's a fixed version <?php $data = <<<SAMPLE PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that = i can have SAMPLE; $data = preg_replace( '/=(?=\\r|\\n)/', '', $data ); echo $data; ?> Outputs PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that i can have Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592603 Share on other sites More sharing options...
ethanhayon Posted July 17, 2008 Author Share Posted July 17, 2008 Refer to my post, it will only remove = followed by a linebreak character. when i use that code, nothing happens Then you're giving us bad sample data. It works fine for me. See bottom of post. You need to use double quotes, not single quotes: $line = preg_replace( "/=(\r|\n)/", '', $line ) No, I don't See below <?php $data = <<<SAMPLE PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that = i can have SAMPLE; $data = preg_replace( '/=(?:\\r|\\n)/', '', $data ); echo $data; ?> Outputs PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that i can have Which is wrong anyways... here's a fixed version <?php $data = <<<SAMPLE PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that = i can have SAMPLE; $data = preg_replace( '/=(?=\\r|\\n)/', '', $data ); echo $data; ?> Outputs PROBLEM CODE: Level 5 PROBLEM: i get a messege that i have exceeded the number of devices that i can have I ended up finding a different and simpler solution. This is what I did: $text = str_replace("=\r", " ", $email_message); Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592616 Share on other sites More sharing options...
discomatt Posted July 17, 2008 Share Posted July 17, 2008 That works as well, assuming your input data is always broken with \r\n and not just \n. But that's doing exactly what my snippet was doing, only mine is slightly more flexible and adapts for a larger range of possible input data. Quote Link to comment https://forums.phpfreaks.com/topic/115245-php-string-manipulation/#findComment-592629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.