note 56036 deleted from function.preg-split by tularis

From: Date: Thu, 03 May 2007 22:25:26 +0000
Subject: note 56036 deleted from function.preg-split by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126175@lists.php.net to get a copy of this message
Note Submitter: afterlife69 [at] GamerzVault.com ---- This is something ive needed for awhile, a way to limit the length of a string. <?php function limit_length($string, $length) { $chars = preg_split('//', $string, -1, PREG_SPLIT_NO_EMPTY); for($i = 0; $i < intval($length); $i++) { if(!empty($new_str)) { $new_str .= $chars[$i]; } else { $new_str = $chars[$i]; } } return $new_str; } $str = sha1('string'); echo limit_length($str, 32); ?> 32Char SHA1 will trick them anyday ^^

« previous php.notes (#126175) next »