Skip to content

Commit

Permalink
added helper functions to misc for alphanumeric and numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris DeGroat committed Sep 16, 2014
1 parent 434e708 commit ea9d3ad
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions misc.php
Expand Up @@ -20,8 +20,10 @@ public static function user_ip()
public static function reindex($array, $field)
{
$new_array = array();
$array = (array) $array;
foreach($array as $a)
{
$a = (array) $a;
$new_array[$a[$field]] = $a;
}
return $new_array;
Expand All @@ -38,6 +40,16 @@ public static function get_between($string, $before, $after, $trim_whitespace =
}
return $result;
}

public static function alphanumeric($string)
{
return preg_replace("/[^A-Za-z0-9 ]/", '', $string);
}

public static function numeric($string)
{
return preg_replace("/(^\s+)|(\s+$)/us", "", preg_replace("/[^0-9\.]/", '', $string));
}
}

?>

0 comments on commit ea9d3ad

Please sign in to comment.