Skip to content

Instantly share code, notes, and snippets.

@chrisveness chrisveness/clean.php
Last active Aug 29, 2015

Embed
What would you like to do?
Clean up posted data
<?php
/**
* Cleans up posted data - trims texts & converts empty fields to null.
*
* @param mixed[] $post POST data to be cleaned.
* @return mixed[] Cleaned-up POST data.
*/
function clean($post)
{
foreach ($post as $key=>$val) if (is_string($val)) $post[$key] = trim($val);
foreach ($post as $key=>$val) if ($val === '') $post[$key] = null;
return $post;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.