|
Posted by denisb on 04/04/07 22:24
CoreyWhite <CoreyWhite@gmail.com> wrote:
> I need to assign all characters the values 1-26, and add them up in
> the string, each time multiplying the next characters value by
> 10^string placement. It should look something like this:
> C 3
> O 150
> R 1,800
> E 5,000
> Y 250,000
> ----------------
> 256,953
> The end result of the word Corey is the number 256,953.
// $my_word in [a-zA-Z] !!!
function codeMyWord($my_word) {
$word_coded = 0;
for ($i = 0; $i < strlen($my_word); $i++) {
$word_coded += (ord(strtoupper($my_word{$i})) - 64) * pow(10, $i);
}
return number_format($word_coded);
}
echo codeMyWord('CoreyWhite'); //--> 7,100,556,953
--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
[Back to original message]
|