Just starting out? Need help? Post your questions and find answers here.
ehbarba
 
Posts: 18
Joined: Thu Mar 29, 2018 2:20 am

How to Encode/Decode HTML Entities?

by ehbarba Mon May 07, 2018 4:41 pm

Is there a way to Encode/Decode HTML Entities?

Greetings

Ezequiel
User avatar
Peter
 
Posts: 479
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: How to Encode/Decode HTML Entities?

by Peter Mon May 07, 2018 5:13 pm

Code: Select all
Procedure.s EncodeHTML(HTML.s)
  ! return $('<div />').text(v_html).html();
EndProcedure

Procedure.s DecodeHTML(Text.s)
  ! return $('<div />').html(v_text).text();
EndProcedure

Debug EncodeHTML("Some text with <div>html</div>")
Debug DecodeHTML("Some text with &lt;div&gt;html&lt;/div&gt;")

(Inspired by: https://coderwall.com/p/jt7ysq/encode-string-to-html-entities-via-jquery)

Greetings ... Peter
ehbarba
 
Posts: 18
Joined: Thu Mar 29, 2018 2:20 am

Re: How to Encode/Decode HTML Entities?

by ehbarba Mon May 07, 2018 6:21 pm

Thank you Peter.

It works great.

Ezequiel
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 1 guest