function strip_tags(str, allowed_tags) { // Strip HTML and PHP tags from a string // // + discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_strip_tags/ // + version: 811.1812 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Luke Godfrey // + input by: Pul // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + bugfixed by: Onno Marsman // + input by: Alex // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + input by: Marc Palau // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: strip_tags('

Kevin


van Zonneveld', ''); // * returns 1: 'Kevin van Zonneveld' // * example 2: strip_tags('

Kevin van Zonneveld

', '

'); // * returns 2: '

Kevin van Zonneveld

' // * example 3: strip_tags("Kevin van Zonneveld", ""); // * returns 3: 'Kevin van Zonneveld' var key = '', tag = '', allowed = false; var matches = allowed_array = []; var replacer = function(search, replace, str) { return str.split(search).join(replace); }; // Build allowes tags associative array if (allowed_tags) { allowed_array = allowed_tags.match(/([a-zA-Z]+)/gi); } str += ''; // Match tags matches = str.match(/(<\/?[^>]+>)/gi); // Go through all HTML tags for (key in matches) { if (isNaN(key)) { // IE7 Hack continue; } // Save HTML tag html = matches[key].toString(); // Is tag not in allowed list? Remove from str! allowed = false; // Go through all allowed tags for (k in allowed_array) { // Init allowed_tag = allowed_array[k]; i = -1; if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+'>');} if (i != 0) { i = html.toLowerCase().indexOf('<'+allowed_tag+' ');} if (i != 0) { i = html.toLowerCase().indexOf(' Remove'; elem.appendChild(newdiv); } function addInputFile(id,nr) { var elem = document.getElementById('elem_'+id); var num = document.getElementById('count_'+nr); var increment = parseInt(document.getElementById('count_'+nr).value)+1; num.value = increment; var newdiv = document.createElement('div'); var divIdName = nr+'_'+increment+'Div'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = 'File Keywords Remove'; elem.appendChild(newdiv); } function addInputText(id,nr) { var elem = document.getElementById('elem_'+id); var num = document.getElementById('count_'+nr); var increment = parseInt(document.getElementById('count_'+nr).value)+1; num.value = increment; var newdiv = document.createElement('div'); var divIdName = nr+'_'+increment+'Div'; newdiv.setAttribute('id',divIdName); newdiv.innerHTML = 'Field name Remove'; elem.appendChild(newdiv); } function removeElement(divNum) { var olddiv = document.getElementById(divNum); olddiv.innerHTML=''; }