Skip to content

Instantly share code, notes, and snippets.

@vodolaz095
Created August 20, 2011 16:04
Show Gist options
  • Save vodolaz095/1159273 to your computer and use it in GitHub Desktop.
Save vodolaz095/1159273 to your computer and use it in GitHub Desktop.
Filter ajax post request with message to cp1251 with code filtering
function filter($a,$ajax=false)
{
/*
*Filter text messages created by ajax post request to mysql insertions, also all malicious tags (scripts, frames et cetera are removed)
*/
if ($ajax) $a=iconv('UTF-8','WINDOWS-1251',urldecode($a));
$a=trim($a);
$a=preg_replace('~<script.*>.*</script>~im',NULL,$a);
$a=preg_replace('~<iframe.*>.*</iframe>~im',NULL,$a);
$a=preg_replace('~<FRAME\s[^>]*>~im',NULL,$a);
$a=preg_replace('~</?frameset[^>]*>~im',NULL,$a);
$a=preg_replace('~</?NOFRAMES>~im',NULL,$a);
$a=preg_replace('~<([A-z0-9]+)(\s.+)>(.+)</[A-z0-9]>~i','<\\1>\\3</\\1>',$a);
$a=preg_replace("~\s{2,}~im","\n",$a);
$a=mysql_real_escape_string($a);
return $a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment