Write a PHP program to convert word to digit


Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. <?php
  2. function word_digit($word) {
  3. $warr = explode(';',$word);
  4. $result = '';
  5. foreach($warr as $value){
  6. switch(trim($value)){
  7. case 'zero':
  8. $result .= '0';
  9. break;
  10. case 'one':
  11. $result .= '1';
  12. break;
  13. case 'two':
  14. $result .= '2';
  15. break;
  16. case 'three':
  17. $result .= '3';
  18. break;
  19. case 'four':
  20. $result .= '4';
  21. break;
  22. case 'five':
  23. $result .= '5';
  24. break;
  25. case 'six':
  26. $result .= '6';
  27. break;
  28. case 'seven':
  29. $result .= '7';
  30. break;
  31. case 'eight':
  32. $result .= '8';
  33. break;
  34. case 'nine':
  35. $result .= '9';
  36. break;
  37. }
  38. }
  39. return $result;
  40. }
  41.  
  42. echo word_digit("nine;five;three;one;six;eight")."<br>";
  43. echo word_digit("one;five;eight")."\n";
  44. ?>

Result

python language techstudy.org

     





Related Topics




Popular Posts