sowna Posted August 1, 2012 Share Posted August 1, 2012 Hi could you tell me how to strip attributes onclick, onmouseover, onchange, etc... from all the html tags. I searched google and got below code but strips all the attributes in the html tags, function stripArgumentFromTags( $htmlString ) { $regEx = '/([^<]*<\s*[a-z](?:[0-9]|[a-z]{0,9}))(??:\s*[a-z\-]{2,14}\s*=\s*(?:"[^"]*"|\'[^\']*\'))*)(\s*\/?>[^<]*)/i'; // match any start tag $chunks = preg_split($regEx, $htmlString, -1, PREG_SPLIT_DELIM_CAPTURE); $chunkCount = count($chunks); $strippedString = ''; for ($n = 1; $n < $chunkCount; $n++) { $strippedString .= $chunks[$n]; } return $strippedString; } thanks for your help. Quote Link to comment Share on other sites More sharing options...
joe92 Posted August 1, 2012 Share Posted August 1, 2012 Not entirely sure what you are looking for but if it's to remove individual attributes using an onclick or onmouseover event you need to be looking at JavaScript, not RegEx. More specifically, element.removeAttribute("attrName"). Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 1, 2012 Share Posted August 1, 2012 Check out Pear HTML_Safe Quote Link to comment Share on other sites More sharing options...
sowna Posted August 2, 2012 Author Share Posted August 2, 2012 @joe92 - Actually i will get html content from mysql database and while showing it, i have to strip onclick,onmouseover... attributes... hope now you understand why i need this. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 2, 2012 Share Posted August 2, 2012 Check out Pear HTML_Safe Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.