Richard Castera

Application Developer/Designer
  • Home
  • About
  • Projects

Archive for September, 2008

PHP | No Comments | September 16, 2008

PHP – Generate a random password based on length

<?php
function generatePassword($intNumOfChars) {
    if (is_numeric($intNumOfChars) && ($intNumOfChars > 0)) {
	$strChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
	for ($i = 0; $i < $intNumOfChars; $i ++)  {
	    $strPassword .= $strChars[rand(0, strlen($strChars)-1)];
	 }
    }
    return $strPassword;
}
?>
PHP | No Comments | September 10, 2008

PHP – 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.

<?php
function truncateString($intLength = 0, $strText = "") {
    if ($intLength == 0) {
        return $strText;
    }
    if(strlen($strText) > $intLength) {
        preg_match("/[a-zA-Z0-9]{0, " . $intLength . "}/", $strText, $strNewText);
        return ($strNewText . "...");
    }
    else {
        return $strText;
    }
}
?>
  • Premium Email Templates

    Social Profiles

  • Twitter
  • Facebook
  • LinkedIn
  • Digg
  • Google
  • GitHub

    Last Tweet

  • Beware the heat-seeking Nerf machine-gun coming to a cubicle near you http://om.ly/svHF #fb
  • Follow me
  • Archives

    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • September 2008
    • August 2008
    • July 2008
    • June 2008
  • Categories

    • AJAX
    • Apache
    • Books
    • Drupal
    • Ecommerce
    • Flash
    • Google
    • Javascript
    • jQuery
    • Magento
    • Marketing
    • Mootools
    • My Thoughts
    • MySQL
    • News
    • Photoshop
    • PHP
    • Prototype
    • SEO
    • Web Resources
    • Wordpress
  • My Favorites

    • 37 Signals
    • Andrew Warner
    • Chris Coyier
    • Chris Shiflett
    • Collis Ta'eed
    • Development Seed
    • Drupal
    • HubSpot
    • James Padolsey
    • Joel On Software
    • John Resig
    • jQuery
    • Kevin Rose
    • Life Hacker
    • Magento
    • Mashable
    • Matt Cutts
    • Matt Ryan
    • MySQL
    • NetTuts
    • Noupe
    • Photoshop Tutorials
    • PHP
    • Smashing Magazine
    • Tech Crunch
    • WoorkUp
    • Wordpress

2010 © Copyright. Richard Castera - All Rights Reserved.

Top