Skip to content

Instantly share code, notes, and snippets.

@chrisveness
Last active August 29, 2015 14:02
Show Gist options
  • Save chrisveness/bddda6b9b0759e0eb4db to your computer and use it in GitHub Desktop.
Save chrisveness/bddda6b9b0759e0eb4db to your computer and use it in GitHub Desktop.
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