wiccan8888 Posted November 9, 2006 Share Posted November 9, 2006 Please help me to create a decimal to text converter, for example the user entered 1 the value is one, then if the user entered 123 the value will be onetwothree, or if the user inputted 567 the output will be fivesixseven...please help.... Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/ Share on other sites More sharing options...
JasonLewis Posted November 9, 2006 Share Posted November 9, 2006 well you could do it a few ways. heres one:[code=php:0]<?php$string = "12345";//start to replace values$string = str_replace("1", "one", $string);$string = str_replace("2", "two", $string);$string = str_replace("3", "three", $string);$string = str_replace("4", "four", $string);$string = str_replace("5", "five", $string);$string = str_replace("6", "six", $string);$string = str_replace("7", "seven", $string);$string = str_replace("8", "eight", $string);$string = str_replace("9", "nine", $string);$string = str_replace("0", "zero", $string);echo $string; //returns onetwothreefourfive?> Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-121986 Share on other sites More sharing options...
Psycho Posted November 9, 2006 Share Posted November 9, 2006 Or to simplify that:[code]<?php$string = "12345";$numbers = array ('1','2','3','4','5','6','7','8','9','0');$words = array('one','two','three','four','five','six','seven','eight','nine','zero');$string = str_replace($numbers, $words, $string);echo $string;?>[/code] Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-121991 Share on other sites More sharing options...
wiccan8888 Posted November 10, 2006 Author Share Posted November 10, 2006 men, you're both genius...how did you go that far in PHP, any tips please... Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122515 Share on other sites More sharing options...
Psycho Posted November 10, 2006 Share Posted November 10, 2006 www.php.net Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122734 Share on other sites More sharing options...
Barand Posted November 10, 2006 Share Posted November 10, 2006 or there is something like this http://www.phpclasses.org/browse/file/4296.htmlwhich will print "123"as"One hundred and twenty three" Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122864 Share on other sites More sharing options...
roopurt18 Posted November 11, 2006 Share Posted November 11, 2006 [quote author=wiccan8888 link=topic=114364.msg465847#msg465847 date=1163137539]men, you're both genius...how did you go that far in PHP, any tips please...[/quote]Buy a PHP programming book; read it, practice it, learn it.Buy a MySQL programming book; read it, practice it, learn it.Buy a system administration book; read it, practice it, learn it.Google for every thing else after that. Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122955 Share on other sites More sharing options...
doni49 Posted November 11, 2006 Share Posted November 11, 2006 [quote author=mjdamato link=topic=114364.msg465317#msg465317 date=1163055284]Or to simplify that:[code]<?php$string = "12345";$numbers = array ('1','2','3','4','5','6','7','8','9','0');$words = array('one','two','three','four','five','six','seven','eight','nine','zero');$string = str_replace($numbers, $words, $string);echo $string;?>[/code][/quote]Nice code!You can even simplify it just a little more if you want to.[code]<?php$string = "12345";$words = array('zero','one','two','three','four','five','six','seven','eight','nine');//array_keys will return an array of all the array's keys.$string = str_replace(array_keys($words), $words, $string);echo $string;?>[/code] Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122960 Share on other sites More sharing options...
wiccan8888 Posted November 11, 2006 Author Share Posted November 11, 2006 also thanks mjdamato for helping me on the decryption on my another forum...thanks Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122969 Share on other sites More sharing options...
wiccan8888 Posted November 11, 2006 Author Share Posted November 11, 2006 thanks for the help again... Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122974 Share on other sites More sharing options...
doni49 Posted November 11, 2006 Share Posted November 11, 2006 Actually that's how I learn BEST. Reading existing code. Whether it be in a book or on a web site. Although I HAVE on occasion used a script without really studying it too much, I try to study the code. I've found that this has helped me more than anything else. Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-122978 Share on other sites More sharing options...
Psycho Posted November 11, 2006 Share Posted November 11, 2006 [quote author=doni49 link=topic=114364.msg466301#msg466301 date=1163209076][code]<?php$string = "12345";$words = array('zero','one','two','three','four','five','six','seven','eight','nine');//array_keys will return an array of all the array's keys.$string = str_replace(array_keys($words), $words, $string);echo $string;?>[/code][/quote]Absolutely! In fact, using the key/value pairs would make sense even when converting something other than numbers. For example if converting from English to Spanish, using a single array like this:$words = array ('one' => 'uno', 'two' => 'dos', 'three' => 'tres', 'four' => 'quatro');would be better programatically (reduce errors) and from a readability standpoint rather than using two arrays.@wiccan,I've never read any books. But, I've read pleanty of tutorials. And, I find personal projects that will require me to learn something new. I find I don't really lear something if I'm only following an example in a book. And a big part are forums such as these. I don't know the answer to a lot of the questions I answer when I first read them. Bt I will do a little research or try something to find a solution if I can. Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-123021 Share on other sites More sharing options...
wiccan8888 Posted November 17, 2006 Author Share Posted November 17, 2006 thanks...many thanks...especially to php freaks... >:( Link to comment https://forums.phpfreaks.com/topic/26666-help-decimal-to-text-converter-script/#findComment-125961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.