note 70952 deleted from function.mt-rand by cmb

From: Date: Sun, 19 Jan 2020 08:35:18 +0000
Subject: note 70952 deleted from function.mt-rand by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213911@lists.php.net to get a copy of this message
Note Submitter: David ---- Shouldn't it be a greater than (>) sign rather than a not equal (!=) sign? Because you're just checking to see if it is exactly six. So if it is 7 it, won't try to fix it. So wouldn't this be better? <? //.... if (strlen($random_hex) < "6") // sometimes it returns an only 5, or less, char Hex-Code, hexcode(); // so the function has to be repeat elseif (strlen($random_hex) > "6") // sometimes it returns 7 or more characters //...I don't know how to make it do only six, but your code seems to only check to make sure it doesn't do less than 6; nothing to counter doing more than 6.... so here would be some code to reduce the size back to 6 if it went over. else echo $random_hex; // returns the Hex-Code } //... ?>

« previous php.notes (#213911) next »