Jump to content

make a number narrowed into a certain number of digits


jwk811

Recommended Posts

[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]
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]
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.