note 110103 added to filter.filters.sanitize
| From: | googlybash24 at aol dot com | Date: | Wed, 19 Sep 2012 17:39:02 +0000 |
| Subject: | note 110103 added to filter.filters.sanitize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190883@lists.php.net to get a copy of this message | ||
Remember to trim() the $_POST before your filters are applied:
<?php
// We trim the $_POST data before any spaces get encoded to "%20"
// Trim array values using this function "trim_value"
function trim_value(&$value)
{
$value = trim($value); // this removes whitespace and related characters from the beginning and end
of the string
}
array_filter($_POST, 'trim_value'); // the data in $_POST is trimmed
$postfilter = // set up the filters to be used with the trimmed post array
array(
'user_tasks' => array('filter' => FILTER_SANITIZE_STRING,
'flags' => !FILTER_FLAG_STRIP_LOW), // removes tags. formatting code is encoded -- add
nl2br() when displaying
'username' => array('filter' => FILTER_SANITIZE_ENCODED,
'flags' => FILTER_FLAG_STRIP_LOW), // we are using this in the url
'mod_title' => array('filter' => FILTER_SANITIZE_ENCODED,
'flags' => FILTER_FLAG_STRIP_LOW), // we are using this in the url
);
$revised_post_array = filter_var_array($_POST, $postfilter); // must be referenced via a variable
which is now an array that takes the place of $_POST[]
echo (nl2br($revised_post_array['user_tasks'])); //-- use nl2br() upon output like so, for
the ['user_tasks'] array value so that the newlines are formatted, since this is our HTML
<textarea> field and we want to maintain newlines
?>
----
Server IP: 69.147.83.197
Probable Submitter: 71.172.140.197
----
Manual Page -- http://www.php.net/manual/en/filter.filters.sanitize.php
Edit -- https://master.php.net/note/edit/110103
Del: integrated -- https://master.php.net/note/delete/110103/integrated
Del: useless -- https://master.php.net/note/delete/110103/useless
Del: bad code -- https://master.php.net/note/delete/110103/bad+code
Del: spam -- https://master.php.net/note/delete/110103/spam
Del: non-english -- https://master.php.net/note/delete/110103/non-english
Del: in docs -- https://master.php.net/note/delete/110103/in+docs
Del: other reasons-- https://master.php.net/note/delete/110103
Reject -- https://master.php.net/note/reject/110103
Search -- https://master.php.net/manage/user-notes.php