Code: Select all
<?php
// stripslash an array
function stripper(&$array) {
foreach ($array as $key=>$value) {
$array[$key] = stripslashes($value);
}
}
// above fn avoids lots of stripslashing and so tidies up the code
// commonly used on $result arrays eg:
while ($result = mysql_fetch_assoc($query)) {
stripper($result);
// ..other code
}
// other utilities I use to tidy up code:
// process vars for db insertion
function dbSafe(&$array) {
foreach ($array as $key=>$value) {
$array[$key] = mysql_escape_string($value);
}
}
// browser safe array
function formSafe(&$array) {
foreach ($array as $key=>$value) {
$array[$key] = htmlspecialchars(trim($value));
}
}
// prepare an array for db storage
function dbSafeArray(&$array) {
$array = serialize($array);
$array = mysql_escape_string($array);
}
// restore a serialized array retrieved from db
function dbRestoreArray(&$array) {
$array = unserialize($array);
reset($array);
stripper($array);
}
?>