jwk811 Posted December 30, 2006 Share Posted December 30, 2006 i have a random number generator and once it gets the number it puts it into md5 to make it more random.. md5 turns it into 25 digits how could i make it into 10 digits ? since it doesnt matter what is taken off Quote Link to comment Share on other sites More sharing options...
fert Posted December 30, 2006 Share Posted December 30, 2006 [code]$num=substr($num,0,9);[/code[[/code] Quote Link to comment Share on other sites More sharing options...
Nhoj Posted December 30, 2006 Share Posted December 30, 2006 [code=php:0] function ShortenText($text) { // Change to the number of characters you want to display $chars = 25; $text = $text." "; $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; return $text; }[/code]To execute that just do..[code=php:0]$number = md5(random());ShortenText($number);[/code] Quote Link to comment Share on other sites More sharing options...
jwk811 Posted December 30, 2006 Author Share Posted December 30, 2006 great thanks Quote Link to comment Share on other sites More sharing options...
jwk811 Posted December 30, 2006 Author Share Posted December 30, 2006 i thought md5 made the text into all digits... is there a way to do that like md5 does except make it into all digits and no letters? Quote Link to comment Share on other sites More sharing options...
Nhoj Posted December 30, 2006 Share Posted December 30, 2006 I'm a little confused as to what you're trying to do, md5 is a one way encryption method. It is always a static 32 character string, if you did [code=php:0]md5(123123);[/code] two times you'd come out with the same exact thing.If you just want to truncate your random number you could do something like...[code=php:0]$num = mt_rand();$num = substr($num,0,9);echo $num;[/code] Quote Link to comment Share on other sites More sharing options...
.josh Posted December 30, 2006 Share Posted December 30, 2006 if you want number only, why are you even bothering with md5? I mean, if you're talking about just getting a random 10 digit number, there's really no such thing as "more" random. Just do like:[code]$num = rand(1000000000,9999999999);// or$num = mt_rand(1000000000,9999999999);[/code] Quote Link to comment Share on other sites More sharing options...
jwk811 Posted January 1, 2007 Author Share Posted January 1, 2007 i just did rand() and got rid of the point and made it 10 digits Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.