Common Functions - El Forum - 01-30-2009
[eluser]jwindhorst[/eluser]
I create a helper class called custom_functions.php. Inside here I store all sorts of generic functions that I need all the time, and thought posting them here might help out some other Igniters, or possibly, get some people to post out some of their own custom functions.
Most of these are pretty basic, but you'll get the idea:
Code: function _pr($a)
{
echo "<pre style='padding: 12px; color: #330077; border:1px solid #FF8800; background-color: #FFFF99; opacity:0.4; filter:alpha(opacity=40);'>";
print_r($a);
echo "</pre>";
}
/**
* @function _vd($a) simply displays the passed in array via var_dump(), wrapped in pre tags.
* @param $a is an array that needs to be displayed.
**/
function _vd($a)
{
echo "<pre style='padding: 12px; color: #330077; border:1px solid #FF8800; background-color: #FFFF99; opacity:0.4; filter:alpha(opacity=40);'>";
var_dump($a);
echo "</pre>";
}
/**
* @function br2nl should convert br tags back to new lines
* @param $string is the string that contains the br's
**/
function br2nl($string)
{
return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string);
}
/**
* @function _vd($a) simply displays the passed in array via var_dump(), wrapped in pre tags.
* @param $s is the string to display.
* @param $l is an optional label for the debug box.
**/
function debug($s,$l=false)
{
echo "<br/>";
echo "<br/>";
if($l)
{
echo "<span style='padding: 12px;margin-right: 12px; border: 1px solid #330077; color: #330077;'>";
echo $l;
echo "</span>";
echo " <strong> => </strong> ";
}
echo "<span style='padding: 12px; color: #330077; border:1px solid #FF8800; background-color: #FFFF99; opacity:0.4; filter:alpha(opacity=40);'>";
echo $s;
echo "</span>";
echo "<br/>";
echo "<br/>";
}
/**
* @function setNotEmpty tests to make sure the passed in value is set, and that it is not empty.
* this is used to fix the idea that the empty function in PHP will return true for a value of 0 (zero)
* @param $v some variable.
**/
function setNotEmpty($v)
{
if(isset($v) && $v != "")
return true;
else
return false;
}
/**
* @ function string_to_mysql_date($str) simply converts our standard date format to something mysql can play more nicely with.
* @ param $str is a string version of the date. Presumable in December 1, 2008 format.
**/
function string_to_mysql_date($str)
{
$months = unserialize(MONTHS);
$str = str_replace(",","", $str);
list($month, $day, $year) = explode(" ", $str);
$months_f = array_flip($months);
$month = $months_f[strtolower($month)];
return "$year-$month-$day";
}
Like I said, they are very basic, even shortcuts some of them, but I love them!
Got some of your own? Love to see them.
|