Deprecated: Assigning the return value of new by reference is deprecated in /home/bluestat/public_html/source/index.php on line 477
.
namespace phalanx\base;
// Iterates over an array and unsets any empty elements in the array. This
// operates on the parameter itself.
function ArrayStripEmpty(Array & $array)
{
foreach ($array as $key => $value)
if (is_array($array[$key]))
ArrayStripEmpty($array[$key]);
else if (empty($value))
unset($array[$key]);
}
// Turns an under_scored string into a CamelCased one. If |$first_char| is
// TRUE, then the first character will also be capatalized.
function UnderscoreToCamelCase($string, $first_char = TRUE)
{
if ($first_char)
$string[0] = strtoupper($string[0]);
return preg_replace_callback('/_([a-z])/', function($c) { return strtoupper($c[1]); }, $string);
}
// Turns a CamelCase string to an under_scored one.
function CamelCaseToUnderscore($string)
{
$string = preg_replace('/([A-Z]+)([A-Z][a-z])/','\1_\2',$string);
$string = preg_replace('/([a-z])([A-Z])/','\1_\2', $string);
return strtolower($string);
}
// Creates a random string of length |$length|, or a random length between 20
// and 100 if NULL.
function Random($length = NULL)
{
if ($length === NULL)
$length = rand(20, 100);
$string = '';
for ($i = 0; $i < $length; $i++)
{
$type = rand(0, 300);
if ($type < 100)
$string .= rand(0, 9);
else if ($type < 200)
$string .= chr(rand(65, 90));
else
$string .= chr(rand(97, 122));
}
return $string;
}