What if we need one in JavaScript? Here's how to do just that!
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script language="javascript" type="text/javascript"> <!-- function htmlEncode(value) { return $('<div/>').text(value).html(); } function htmlDecode(value) { return $('<div/>').html(value).text(); } var s = "<b>hello's world</b>"; var encoded = htmlEncode(s); var decoded = htmlDecode(encoded); alert(encoded); alert(decoded); //--> </script>