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
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(''+allowed_tag) ;} // Determine if (i == 0) { allowed = true; break; } } if (!allowed) { str = replacer(html, "", str); // Custom replace. No regexing } } return str; } function postStringForm(docForm) { var submitContent = ''; var formElem; var lastElemName = ''; for (i = 0; i < docForm.elements.length; i++) { formElem = docForm.elements[i]; switch (formElem.type) { // Text fields, hidden form elements case 'text': case 'hidden': case 'password': case 'textarea': case 'select-one': submitContent += formElem.name + '=' + escape(formElem.value) + '&' break; // Radio buttons case 'radio': if (formElem.checked) { submitContent += formElem.name + '=' + escape(formElem.value) + '&' } break; // Checkboxes case 'checkbox': if (formElem.checked) { // Continuing multiple, same-name checkboxes if (formElem.name == lastElemName) { // Strip of end ampersand if there is one if (submitContent.lastIndexOf('&') == submitContent.length-1) { submitContent = submitContent.substr(0, submitContent.length - 1); } // Append value as comma-delimited string submitContent += ',' + escape(formElem.value); } else { submitContent += formElem.name + '=' + escape(formElem.value); } submitContent += '&'; lastElemName = formElem.name; } break; } } // Remove trailing separator submitContent = submitContent.substr(0, submitContent.length - 1); return submitContent; } function getPageWithoutRedir(page, div, id){ //page = fisier prelucrare, div= element care se actualizeaza var param = "id="+id; res = ajaxUpdate( div, page, { params:param, meth:"post", async:true, startfunc:"onById('loading')", endfunc:"offById('loading'); onById('"+div+"');", errorfunc:"ajaxError()" } ); return false; } function getPage(page, div, redirTo, formData, loadingDiv){ if(loadingDiv=='') loadingDiv = 'AJAXloading'; //daca ajax response este gol si redirTo este setat se face redirectare //page = fisier prelucrare, div= element care se actualizeaza, loadingDiv - idul elementul care se afiseaza cand se face loading var param = formData; res = ajaxUpdate( div, page, { params:param, meth:"post", async:true, startfunc:"onById('"+loadingDiv+"')", endfunc:"offById('"+loadingDiv+"'); onById('"+div+"');redir('"+redirTo+"', '"+div+"')", errorfunc:"ajaxError()" } ); return false; } function redir(url, div){ //url pagina catre care se face redirectul, div = divul in care se afiseaza raspunul if(getById(div).innerHTML==''){ if(url!='') window.location=url; } } function onById(id){ document.getElementById(id).style.visibility = "visible"; } function offById(id){ document.getElementById(id).style.visibility = "hidden"; } function ajaxError(){ alert( "There was an error encountered while performing the request. Please try again later." ); } function getById(id){ return document.getElementById(id); } function MsgBox(msg,msg1) { spring = window.confirm(msg1); if (spring == true) openNewWindow(msg); } function openNewWindow(msg) { window.location = msg; } function toggle(id){ if (document.getElementById(id).style.display=='none') document.getElementById(id).style.display=''; else document.getElementById(id).style.display='none'; } function addInput(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 = ' 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=''; }