hello,

I want to assign certain numbers to the alphabets i.e. from A-Z (case insensitive),
the numbers will range from 0-9 and will not go in the two digits.

how can I assign the numbers to alphabets?

and suppose an user enters his name as: chandan
then it should assign the number and add in the folloing manner :
c+h+a+n+d+a+n
9+5+2+3+6+1+0= 26 = 2+6 = 8

i.e. it should return 8.

How can I do this ?

Please let me know?

Thanking you!

    what algorithm do you want to use for the alpha-number assigments? your code example does not seem to suggest anything specific. what ever it is i suggest you create an array with the letters as the keys and the numbers as the values then just loop thru the string and replace each character. during each loop iteration you can also do the math.

      Is this some kind of cryptation or hashing? If it is I strongly suggest using something that is safer than this.

        I suppose you could do it by defining an array where the keys are letters and the values are the numbers assigned to those letters, then loop through each character of the string and grab the numbers, etc. However, if you were to explain to us why you feel you need to do such a convoluted thing, we might be able to suggest a simpler and cleaner alternative. For instance, if the purpose is to generate a sort of single-digit checksum for the specified string, you could just do:

        $checksum = substr(sprintf('%u', crc($string)), -1);
        
          Write a Reply...