Convert HTML Entities -- JavaScript -- Free Code Camp

preview_player
Показать описание

**Convert HTML Entities** -- Escaping characters. Replacing characters in a string with values from an object literal.
Рекомендации по теме
Комментарии
Автор

Incredible solution!!!
I never know I can do this reading those stupid documents until I saw this

Автор

Thanks again. Nice solution. I think an object literal makes code really clear when dealing with a lot of keys/values. I used the replace method, and although it appears to be less code, I think your code is easier to read and follow.

function convertHTML(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
}

supersteve
Автор

Nice work Steve....great explanation. Appreciate you going step by step through each component

dg
Автор

This is actually a very good explanation. Thumbs up buddy!

asadrauf
Автор

Very good solution and excellent explanation as usual! Keep it up!

elminster
Автор

this was helpful. simple and effective solution! but i just feel u can speak faster :p

lycan
Автор



as i said i am using ajax and a jquery so i don't really know where to put htmlentities() in my site.


thanks in advance

Ramaihaholic