Richard on Sep 16th, 2008PHP - Generate a random password based on length
function generate_password($int_num_of_chars)
{
if (is_numeric($int_num_of_chars) && ($int_num_of_chars > 0))
{
$str_chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
for ($i = 0; $i < $int_num_of_chars; $i ++)
{
$str_password .= $str_chars[rand(0, strlen($str_chars)-1)];
}
}
[…]
Richard on Sep 10th, 2008PHP - Truncate a string to a given length
This is a function I use to display the ellipses when I want to truncate and display a summary of a larger body of text.
function truncate_string($int_length = 0, $str_text = "")
{
if ($int_length == 0)
{
return $str_text;
}
if(strlen($str_text) > $int_length)
{ […]

