Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/115245-php-string-manipulation/
Share on other sites

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

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.

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

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);

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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