Strip all javascript from HTML
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Strip all javascript from HTML

  1. #1
    Join Date
    Aug 2010
    Posts
    77

    Strip all javascript from HTML

    Does anyone happen to have a PHP script that can strip all javascript from HTML leaving the HTML tags, but removing the attributes for scripted events and script tags?

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,877

    Re: Strip all javascript from HTML

    1. Create an array of all JavaScript events (onclick, onkeypress, etc.).
    2. Use preg_replace() to remove all contents inside.
    3. Use preg_replace() to remove all <script> tags.
    4. Use preg_replace() to remove all instances of "javascript:..."
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center