Tuesday, 26 July 2016

How to decode encoded html entities in javascript:

<?php

/**
* Decode a string with encoded characters like &amp;
* @param string encodedString - string to encode
* @return string
*/
function decodeEntities(encodedString) {
  var textArea = document.createElement('textarea');
  textArea.innerHTML = encodedString;
  return textArea.value;
}

console.log(decodeEntities("Keith & Hards"));

output: "Keith & Hards"




 

No comments:

Post a Comment