note 57821 deleted from function.uniqid by bjori

From: Date: Tue, 11 Apr 2006 20:59:39 +0000
Subject: note 57821 deleted from function.uniqid by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107809@lists.php.net to get a copy of this message
Note Submitter: dyer85 at gmail dot com ---- Concerning the previous user's class: I'm not sure what you were attempting, but your overall usage of the class has some syntax errors and concept misapplications. For example, the NewGuid method is wrong and not needed. Instead, try: <?php class Guid { var $guidText; function Guid() { $this->guidText = md5(uniqid(rand(),true)); return $this->guidText; } function toString($separator = '', $case = false) { $str =& $this->guidText; if ($case) { switch ($case) { case 'uc': $str = strtoupper($str); break; case 'lc': $str = strtolower($str); break; default: $str = $str; } } $str = substr($str,0,8) . $separator . substr($str,8,4) . $separator . substr($str,12,4). $separator . substr($str,16,4). $separator . substr($str,20); return htmlspecialchars($str); } // do some other stuff } $obj = new Guid(); echo 'Dash: ' . $obj->toString('-'); echo 'Lower-case with "?" as separator: ' . $obj->toString('?', 'lc'); ?> This method just gives a bit more options, so if you want different methods to do different things or whatever.

« previous php.notes (#107809) next »