_tina_ Posted June 30, 2009 Share Posted June 30, 2009 Hi, I have an email address that I'm passing as a parameter. I need to convert email addresses that may have a plus sign "+" in them to the appropriate value. For instance, if the user submits their email address as user+userB@email.com, I am using urlencode and on the following page, I am getting user userB@email.com which is understandable. Is there some way I can get around this? I was thinking of something like: if( the email has a plus in it ) replace that with the proper code so the next page will understand and insert a + instead of a space End if I hope this makes sense and thank you in advance Quote Link to comment Share on other sites More sharing options...
abdfahim Posted June 30, 2009 Share Posted June 30, 2009 can you tell me how u r passing this email? using GET method? Quote Link to comment Share on other sites More sharing options...
flyhoney Posted June 30, 2009 Share Posted June 30, 2009 Depends! Gmail and other clients ignore everything after the plus, which allows people to filter spam effectively. If you are using this to foil people's attempt to divert spam, I don't think you deserve help However, if you have a non malicious reason for doing this, maybe I will give you a hint. Quote Link to comment Share on other sites More sharing options...
jmr3460 Posted June 30, 2009 Share Posted June 30, 2009 Can you explode(with + being the exploding point) then implode(with @ being the implode point) Is the email in a form field or something? You may also be able to use ereg_match() this looks for a regular expression and if it has the "+" then explode(+) then I think you can implode(@). Maybe something like that. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted June 30, 2009 Share Posted June 30, 2009 <?php $string = 'spammers+areassholes@wtf.com'; $pattern = '/\+[^@]+/i'; echo preg_replace($pattern, '', $string); Quote Link to comment Share on other sites More sharing options...
.josh Posted June 30, 2009 Share Posted June 30, 2009 hmm...have you looked into urlencode or htmlentities? Quote Link to comment Share on other sites More sharing options...
_tina_ Posted June 30, 2009 Author Share Posted June 30, 2009 Thanks for all the replies. I have looked into urlencode, apparently though, it is urlencode which add's the "+" in the first place and rawurlencode isn't an option. I am passing the paramaters along with a link i.e. <a href=link.com?param=1¶m2=email etc. There is no maliciousness here on my part! It's just the client uses a "+" in his email address and wants to be able to do so in this system. Thanks again for all the replies. Quote Link to comment Share on other sites More sharing options...
_tina_ Posted June 30, 2009 Author Share Posted June 30, 2009 <?php $string = 'spammers+areassholes@wtf.com'; $pattern = '/\+[^@]+/i'; echo preg_replace($pattern, '', $string); Thanks for this. Just one question, I gather that this will strip out the + sign and leave 'spammersareassholes@wtf.com', is this correct? If so, how do I get the original email address, with the + sign, back on the next page? Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 30, 2009 Share Posted June 30, 2009 and rawurlencode isn't an option. Why not? Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 30, 2009 Share Posted June 30, 2009 I agree with DanielO, why not rawurlencod()? That's what it is there for. But assuming you have a good reason (which I can't think of one) a solution would be to replace plus signs with an alternative character (that isn't used in emails) before passing on the query string. Then replace it back to plus signs on the receiving page before using. But, again, there's no logical reason not to use rawurlencode(). Quote Link to comment Share on other sites More sharing options...
_tina_ Posted June 30, 2009 Author Share Posted June 30, 2009 Would it work if I checked for an email address with a + and if there is one then replace t with a "%2B"? Quote Link to comment Share on other sites More sharing options...
_tina_ Posted June 30, 2009 Author Share Posted June 30, 2009 I agree with DanielO, why not rawurlencod()? That's what it is there for. But assuming you have a good reason (which I can't think of one) a solution would be to replace plus signs with an alternative character (that isn't used in emails) before passing on the query string. Then replace it back to plus signs on the receiving page before using. But, again, there's no logical reason not to use rawurlencode(). Thanks for that, the reason I can't use rawurlencode is because I'm doing this project using the Symfony framework which is new to me and I can't it uses urlencode by default and there I can't seem to get it to use rawurlencode. This is why I'm looking for a work around. Like I said above, maybe replacing the + in an email with a %2B might solve this. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 30, 2009 Share Posted June 30, 2009 How exactly are you doing it? It's just a matter of doing $email = rawurlencode($email); and then passing it to whatever you want. Quote Link to comment Share on other sites More sharing options...
_tina_ Posted June 30, 2009 Author Share Posted June 30, 2009 How exactly are you doing it? It's just a matter of doing $email = rawurlencode($email); and then passing it to whatever you want. That's exactly how I'm doing it ^. It's having no effect though. It seems to just completely ignore it. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 30, 2009 Share Posted June 30, 2009 echo rawurlencode('foo+bar@example.com'); outputs foo%2Bbar%40example.com on my system, like it should. What do you mean with it doesn't have any effect? Quote Link to comment Share on other sites More sharing options...
_tina_ Posted June 30, 2009 Author Share Posted June 30, 2009 echo rawurlencode('foo+bar@example.com'); outputs foo%2Bbar%40example.com on my system, like it should. What do you mean with it doesn't have any effect? Yes, it does this on my system too. However when I do this in Symfony, it has no effect, i.e. it completely ignores it and add's a "+". Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted June 30, 2009 Share Posted June 30, 2009 I'm afraid you'll have to show us the code where you are trying to do this then. Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 30, 2009 Share Posted June 30, 2009 Well, you are doing something wrong. I installed the symfony framework and modified the example project to add the test above and it works perfectly. Might I suggest NOT using a framework until you have mastered PHP. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted June 30, 2009 Share Posted June 30, 2009 <?php $string = 'spammers+areassholes@wtf.com'; $pattern = '/\+[^@]+/i'; echo preg_replace($pattern, '', $string); Thanks for this. Just one question, I gather that this will strip out the + sign and leave 'spammersareassholes@wtf.com', is this correct? If so, how do I get the original email address, with the + sign, back on the next page? This removes the '+' and everything between it and the '@' Quote Link to comment 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.