You are here:
» What Is PHP Strip_tags() Jquery Quivalent?
What is PHP strip_tags() Jquery quivalent?
This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.
Hi People,
What is PHP strip_tags() Jquery/Javascript equivalent? I have to stip all html tags from content variable in the javascript code that uses Jquery.

1 year 42 weeks ago
Tags:
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>Post Comment