after hours of trying i'm here to ask. i want to remove all the occurences of js event attributes and style attribute from POSTed text. it may or may not contain new lines.
Posted example text:
<a href="http://www.google.com" onclick="unwanted_code" style="unwanted_style" ondblclick="unwanted_code" onmouseover="unwanted_code">google</a> is a search engine. There are other engines too. <a href="http://www.yahoo.com" onclick="unwanted_code" ondblclick="unwanted_code" onmouseover="unwanted_code" style="unwanted_style">yahoo</a> is another engine.
first try:
$pattern[0] = '/(<[^>]+) on.*=".*?"/iU';
$replace[0] = '$1';
$pattern[1] = '/(<[^>]+) style=".*?"/iU';
$replace[1] = '$1';
$out = preg_replace($pattern, $replace, $in);
output:
<a href="http://www.google.com">yahoo</a> is another engine.
second try:
$out = preg_replace_callback('/(<[^>]+) on.*=".*?"/iU', function($m) {return $m[1];}, $in);
output:
<a href="http://www.google.com">yahoo</a> is another engine.
output i'm trying to get is:
<a href="http://www.google.com">google</a> is a search engine. There are other engines too. <a href="http://www.yahoo.com">yahoo</a> is another engine.
anyone helping me out?
styleit's easy to add if you really want the regex solution.<script>tags?