note 99512 modified in function.str-replace by danbrown
| From: | danbrown@php.net | Date: | Fri, 20 Aug 2010 20:04:38 +0000 |
| Subject: | note 99512 modified in function.str-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171904@lists.php.net to get a copy of this message | ||
<?php
/*
small anti injection for $_POST and $_GET method
example to use
$str = antiinjection($_POST[str])
*/
function antiinjection($str) {
$banwords = array ("'", ",", ";", "--",
"\"", "%", ">", "<"); // bad words
$str = strip_tags($str);
$str = str_replace ( $banwords, '', $str); // replace badwords to null
return $str;
}
$str = "-- hello guys, nice to <br /> know you --";
echo antiinjection($str);
// result is: hello guys nice to know you
// i know it not better, but it work
?>
--was--
<?php
/*
small anti injection for $_POST and $_GET method
example to use
$str = antiinjection($_POST[str])
*/
function antiinjection($str) {
$banwords = array ("'", ",", ";", "--",
"\"", "%", ">", "<"); // bad words
$str = strip_tags($str);
$str = str_replace ( $banwords, '', $str); // replace badwords to null
return $str;
}
$str = "-- hello guys, nice to <br /> know you --";
echo antiinjection($str);
// result is: hello guys nice to know you
// i know it not better, but it work
?>
http://php.net/manual/en/function.str-replace.php