2

I am trying to nest an AMPscript function - Replace(). This should take a value and replace it based on what you designate in the function. However, I have two values I need to replace. The "@" symbol in an email address should be replaced by %2 and the "." symbol in the email should be replaced by %4. This is for use in a URL string where the email address is appendeded to be passed and consumed. Currently I have this:

Set @email = [Email Address]

%%=Replace(Replace(@email,"@","%4"),".","%2")=%%

But it's only replacing the @ and not the ..

Any ideas?

Here is the AMPscript variable block:

<!---ampscript
%%[
/* 101 */ Var @memberfirstname, @memberlastname, @refereefirstname, @refereelastname, @promocode, @rewardpreference, @amountpaid, @email
Set @memberfirstname = member_first_name
Set @memberlastname = member_last_name
Set @refereefirstname= referee_first_name
Set @refereelastname = referee_last_name
Set @promocode = promo_code
Set @rewardpreference = reward_preference
Set @amountpaid = amount_paid
Set @email = [Email Address]


/* 101 */
]%%
/-->

Due to client confidentiality I cannot post the entire URL string. Here is what it looks like without the actual URL:

<a href="https://url.example.com?c=promocode=%%=v(@promocode)=%%&email=%%=Replace(Replace(@email,"@","%40"),".","%2E"=%%"><img border="0" src="http://image.s4.exct.net/lib/fe9015737461027473/m/1/btn-referee-reminder-apply.gif" width="115" height="32" alt="" longdesc=""></a>
5
  • Could you post your entire code block? Reason: if the SET is happening in an AMPscript block, like %%[ ]%%, there will be no need to have %%= =%% later on in the same block. Also, it looks like your %4 and %2 are the opposite in your code compared to your question.
    – Timothy
    Apr 9, 2014 at 17:53
  • I just tried this exact code, and it worked perfectly. Am I missing the issue? Apr 9, 2014 at 18:07
  • It seems that due to the "." being replaced by "%2E", the system is returning the ASCII character "." as opposed to the string "%2E". Apr 9, 2014 at 18:29
  • This section is missing a closing parenthesis - %%=Replace(Replace(@email,"@","%40"),".","%2E"=%% Apr 9, 2014 at 18:33
  • 3
    This question appears to be off-topic because it is about URL encoding and there is actually no issue with the functions as written. Apr 9, 2014 at 20:11

1 Answer 1

1

Your issue lies with the function itself -

Replace this:

%%=Replace(Replace(@email,"@","%40"),".","%2E"=%%

With this:

%%=Replace(Replace(@email,'@','%40'),'.','%2E')=%%

I just dropped this in my account and tested - the resulting link was:

https://url.example.com/?c=promocode=123&email=test%40test%2Ecom
9
  • The same string in my account ( parenthesis corrected - that was a typo) still yields the following when I click the link: ?c=promocode=X1X1&email=ashley.bisesti%40kobie.com where my email is ashley.bisesti@kobie.com. Apr 9, 2014 at 18:50
  • It has something to do with the use of "%2E", because when I replace that with "dot" instead, it works. Is is just using the ASCII character and printing it to the URL? Apr 9, 2014 at 18:52
  • What browser are you using? I'm trying it on chrome, and it's showing up as %2E. Also unsure why the . reverts and not the @. Apr 9, 2014 at 18:54
  • Just tried again on chrome - https://url.example.com/?c=promocode=123&email=test%2Ename%40test%2Ecom. I think it's a browser issue. Apr 9, 2014 at 18:56
  • By issue I just mean, the browser is interpreting the string automatically. Apr 9, 2014 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.