Thanks Feyd!
I tried this code:
$page_part = stripslashes(preg_replace("/onload\s*=\s*\"[^>]*\"/i", '', $page_part));
and it seems to be working. Is there anything wrong with this code? You know, it was kind of...luck that I figured it out
The reason I need this regex is because of a bug / strange behaviour in strip_tags. It works great but in the above example JavaScript code it has problems with this part:
Or actually with the "<" sign in it. For some reason strip_tags stops converting the html content into plain text at that point. When you try to strip tags on this example:
<img src="image.gif" onload="if (this.width<50) {this.src='image2.gif'; this.width='120'; this.height='90'}">
<p>This is some text</p>
It will not output anything. If you get rid of the "<" in the JavaScript code - e.g. change it to (this.width=50), everything will work as expected.
Is there a better fix than getting rid of the JS code completely via preg_replace? If not then I will simply use that but there may be more situations when something like this could happen in my opinion.
Thanks!
Tomas