note 97929 deleted from function.trim by hholzgra

From: Date: Thu, 02 Aug 2012 12:31:35 +0000
Subject: note 97929 deleted from function.trim by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189674@lists.php.net to get a copy of this message
Note Submitter: Onur Nizam ( onur dot nizam at yahoo dot com ) ---- While inserting data from web forms to databases, trimming the posted values to remove the spaces from the left and right sides can be a good idea to avoid the user faults. This code have to be located before the DB operations. <?php /* Stripping whitespaces from left and right sides of all posted data. * Put this before working with posted data. * */ // Remove whitespaces from left and right sides. function removeSpaces($str) { $newStr = trim($str); return $newStr; } // If any data posted to the page, send them for trimming. if ($_POST) { foreach ($_POST as $var => $value) { $value=removeSpaces($value); $_POST[$var] = $value; } } ?>

« previous php.notes (#189674) next »