PHP - 将字符转换为数字

Let's say I have a string like this:

whateverthisis123 #_-

I want to convert this string into a number within a number interval forexample within 1-1000.

The above string could for example be converted into

387

This comes with a few rules:

  • The string could contain every character.
  • The number should feel random but cannot be. The same string should always return the same number.
  • Longer string should not make the number higher. Should feel random.
  • aaa should not give a number like 222. Should feel random.
  • It should accept the interval for example 1 up to 1000.
  • "thisstring" and "thisstring1" are alike. The numbers should still not be alike.

Is there a built in function for this in PHP? If not, any clever idea how to create something like this?

Maybe it's easier if first converting in to MD5? http://www.php.net/manual/en/function.md5.php

Extended from my comment, here is a full code example (more fun way than just hash..)

 <?php
  int numberout(string $input)
      {
         $hash=md5($input);
         $calculate=hexdec(substr($hash,0,3)); //take out 3 digits
         $maxhex=4095; //3 digit hex ,65535 for 4 digit hex and so on...
         $out = ($calculate*1000)/$maxhex;
         return $out;
      }
 ?>

Sorry if this is programmartically wrong, I was used to c# and I haven't test this yet. So if there is any error I hope someone to edit it

You're essentially describing a hash function. MD5 looks like the way to go. If you need to convert it to a number you could intval() it. To keep it between 1-1000, use $number % 1000.

Note: If this has to do with security/passwords, it's a bad idea.