How can I decode sanitized user input from the data

PHP has a function called htmlspecialchars which replaces Characters like

& (ampersand) replaced with &
" (double quote) replaced with "
' (single quote) replaced with '
< (less than) replaced with &lt;
> (greater than) replaced with &gt;
Read More ā†’ [PHP: htmlspecialchars - Manual]

Iā€™m convert my PHP project to elixir and all database entries with those characters are saved with their replacements. How can I convert the string data from the database back to its characters?

Maybe GitHub - martinsvalin/html_entities: Elixir module for decoding HTML entities. can help.

3 Likes

[EDIT] I misread the question, the original request is to decode, not encode, entities.

If you are using Phoenix then the module Phoenix.HTML includes the html_escape/1 function that encodes entities.

2 Likes

Which is actually implemented in Plug.HTML, so no need for the whole lot of phoenix.

2 Likes