M.O.S. Studios Posted June 23, 2011 Share Posted June 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/240221-numbers-to-letters/ Share on other sites More sharing options...
priti Posted June 24, 2011 Share Posted June 24, 2011 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., Quote Link to comment https://forums.phpfreaks.com/topic/240221-numbers-to-letters/#findComment-1234177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.