Jump to content

numbers to letters


M.O.S. Studios

Recommended Posts

I want to  be able to convert numbers to their letter equivalent. However I need it to go past 26 values.

 

here is the code

    function letters($value){
        if(!is_integer($value) && $value > 0){return false;}
        if($value < 26){return base_convert($value+10, 10, 36);}else{
            $tester = $value / 25;
            $tester = explode('.', $tester);
            return base_convert($tester[0]+9, 10, 36).letters($value*($tester[0]) - 26);
        }
    }

    echo $welcome."\n".$questions;
        for($i=0; $i<= 200; $i++){
        echo letters($i).$i."<br>";
    }

 

the problem happens after value 49.

 

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/240221-numbers-to-letters/
Share on other sites

The quick view list two problems

 

1.$tester = $value / 25; to $tester = $value / 26; 

 

This will resolve your problem after value 40

 

secondly, you are calling recursively function letters() and in your function letters() there is not exit condition hence when the value reaches to 52.... it  recursively call letter() function and results in different character string. You need to control the execution of letter() function on some condition.

 

Thanks.,

Link to comment
https://forums.phpfreaks.com/topic/240221-numbers-to-letters/#findComment-1234177
Share on other sites

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.