1

Has anyone attempted to decode HTML entities using AMPscript? For example, I have encoded HTML stored in a data extension:

<p>Dave is great!</p>

I need to use this value in an email but the output is displaying:

<p>Dave is great!</p>

Can AMPscript, or some other feature of the Marketing Cloud, decode the original value before it's called to the email template? Dave needs his credit.

Dave is great!

3 Answers 3

2

Dan, I do not think AMPScript has a feature to decode html entities so my advice would be to use the AMPScript replace() function.

Example -

%%[
SET @Data = "&lt;p&gt;Dave is great! &lt;/p&gt;"

SET @Data1 = Replace(Replace(@Data,"&lt;","<"),"&gt;",">")
]%%
%%=v(@Data1)=%%
0

As stated by others, there is nothing native in Ampscript for this. I am not sure, but potentially using something with the "Format" Ampscript may be a possibility, depending on how extensive the connection with C# string formatting is. I have never used this so I am not sure.

Outside that I would look at using SSJS using HTMLEncode or HTMLDecode as SSJS and AmpScript can interact to a level inside Exact Target. I am not sure if this will work if coded inside an email, but you could try to create a SSJS interaction(need to call Help Desk to add into your account) to pull the info and correctly encode/decode and then fill this now correct info into an AMPScript variable in email using the AMPscript Web API capabilities.

4
  • 1
    Those functions decode HTML entities? Commented Jun 21, 2015 at 22:25
  • I misread some I believe. He may need to use Replace to decode the less then and greater then into the symbols first then use that ContentArea so it reads it as code and not just a text string when displaying. Commented Jun 22, 2015 at 11:07
  • The TreatAsContent functions will force AMPScript to be evaluated inside the content block. As far as I know, it doesn't have anything to do with HTML entity encoding/decoding. Can you clarify your answer with an example perhaps? Commented Jun 22, 2015 at 16:41
  • After looking at it a bit more thoroughly, I completely misread the question. I thought the issue was that the code was not rendering, not that a solution to decode the HTML was needed from the DE. I am going to edit my answer to include relevant information Commented Jun 23, 2015 at 13:25
0

I was able to do this. I used encodeURIComponent on the client side, then in SFMC with SSJS I did this.

 <script runat="server">
  Platform.Load("Core","1");
  var message = decodeURIComponent(Request.GetFormField("message"));
  Variable.SetValue("@message",message);
</script>

And it works.

In addition, it seems that decodeURIComponent also works after the fact.

  var jsonpost = decodeURI(Platform.Request.GetPostData());
  Write(decodeURIComponent(jsonpost));

This allowed me to grab a form's entire post and also accept html. For example, one of my form fields had a <br> in it, so submission was failing. Changing the <br> in Senior<br>Director to Senior%3Cbr%3EDirector allows the form to be submitted AND converts the html entities.

I was also able to take that and write it to a data extension.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .