I found this here: http://www.stemkoski.com/what-is-javascript%E2%80%99s-equivalent-to-php-strip_tags/
/***************************************************
STRIP HTML TAGS
****************************************************/function strip_tags(html){//PROCESS STRINGif(arguments.length<3){
html=html.replace(/<\/?(?!\!)[^>]*>/gi,'');}else{var allowed = arguments[1];var specified =eval("["+arguments[2]+"]");if(allowed){var regex='</?(?!('+ specified.join('|')+'))\b[^>]*>';
html=html.replace(new RegExp(regex,'gi'),'');}else{var regex='</?('+ specified.join('|')+')\b[^>]*>';
html=html.replace(new RegExp(regex,'gi'),'');}}//CHANGE NAME TO CLEAN JUST BECAUSE var clean_string = html;//RETURN THE CLEAN STRINGreturn clean_string;
The way it would be used:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
/***************************************************
STRIP HTML TAGS
****************************************************/
function strip_tags(html){
//PROCESS STRING
if(arguments.length < 3) {
html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
} else {
var allowed = arguments[1];
var specified = eval("["+arguments[2]+"]");
if(allowed){
var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
html=html.replace(new RegExp(regex, 'gi'), '');
} else{
var regex='</?(' + specified.join('|') + ')\b[^>]*>';
html=html.replace(new RegExp(regex, 'gi'), '');
}
}
//CHANGE NAME TO CLEAN JUST BECAUSE
var clean_string = html;
//RETURN THE CLEAN STRING
return clean_string;
}
</script>
</head>
<script type="text/javascript">
var sample_html = '<h1><a href="http://www.gozipline.com">Zipline Interactive</a></h1>';
document.write('Without Stripping Tags : ' + sample_html);
var demo = strip_tags(sample_html);
document.write('With Stripping Tags: ' + demo);
</script>
<body>
</body>
</html>
I found this here: http://www.stemkoski.com/what-is-javascript%E2%80%99s-equivalent-to-php-strip_tags/
The way it would be used:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript"> /*************************************************** STRIP HTML TAGS ****************************************************/ function strip_tags(html){ //PROCESS STRING if(arguments.length < 3) { html=html.replace(/<\/?(?!\!)[^>]*>/gi, ''); } else { var allowed = arguments[1]; var specified = eval("["+arguments[2]+"]"); if(allowed){ var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>'; html=html.replace(new RegExp(regex, 'gi'), ''); } else{ var regex='</?(' + specified.join('|') + ')\b[^>]*>'; html=html.replace(new RegExp(regex, 'gi'), ''); } } //CHANGE NAME TO CLEAN JUST BECAUSE var clean_string = html; //RETURN THE CLEAN STRING return clean_string; } </script> </head> <script type="text/javascript"> var sample_html = '<h1><a href="http://www.gozipline.com">Zipline Interactive</a></h1>'; document.write('Without Stripping Tags : ' + sample_html); var demo = strip_tags(sample_html); document.write('With Stripping Tags: ' + demo); </script> <body> </body> </html>