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 – 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;
}
}
?>
-
Beware the heat-seeking Nerf machine-gun coming to a cubicle near you http://om.ly/svHF #fb
- Follow me
Last Tweet
-
Archives
Categories
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
