CS Knowledge Opener - Logo
CS Knowledge
Opener
Facebook Youtube Telegram
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
CS Knowledge Opener - Logo
CS Knowledge
Opener
Facebook Youtube Telegram
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
  • Home
  • 12th CS
    • 12th CS English Medium
    • 12th CS Tamil Medium
  • 12th CA
    • 12th CA English Medium
    • 12th CA Tamil Medium
  • 11th CS
    • 11th CS English Medium
    • 11th CS Tamil Medium
  • 11th CA
    • 11th CA English Medium
    • 11th CA Tamil Medium
  • CS / CA Question Bank
  • Other Subjects
  • Student Alerts
  • Govt Exams
12th CA English Medium

Practical program exercise 10 PHP Converting word to digit for 12th computer applications

Baskaran J
February 18, 2023 2 Mins Read
2.1K Views
0 Comments

Program exercise 10 PHP Converting word to digit

Function:

  • A function is created once but used many times, often from more than one program.
  • If the function code changes, the changes are implemented in one spot (the function definition) while the function invocations remain untouched.
  • This fact can significantly simplify code maintenance and upgrades, especially when contrasted with the alternative: manually changing every occurrence of the earlier code wherever it occurs (and possibly introducing new errors in the process).

Creating and Invoking Functions:

  •  Arguments, which serve as inputs to the function
  • Return values, which are the outputs returned by the function
  • The function body, which contains the processing code to turn inputs into outputs

explode()

  • Splits a string into array elements explode() function, which accepts two arguments—the separator and the source string—and returns an array

Example:

<?php

$str = ‘tinker,tailor,soldier,spy’;

$arr = explode(‘,’, $str);

print_r($arr);

?>

foreach:

  • The foreach construct provides an easy way to iterate over arrays.
  • foreach works only on arrays and objects, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable.

Switch Case:

  • The switch case is an alternative to the if.. elseif..else statement which executes a block of code corresponding to the match.

Syntax:

switch (n) {

case label1:

code to be executed if n=label1;

break;

case label2:

code to be executed if n=label2;

break;

case label3:

code to be executed if n=label3;

break;

…

default:

code to be executed if n is different from all labels;

}

CA – 10 PHP – CONVERTING WORD TO DIGIT

QUESTION:

Write a PHP code to convert word to digit in PHP using function with switch…case.

AIM:

To Write a PHP program to convert word to digit.

PROCEDURE:

  1. Start Xampp server (Apache)
  2. Go to virtual path folder (C:\xampp\htdocs)
  3. Create digit.php file and type the program
  4. Execute the program on your Web browser using by this URL link (http://localhost/digit.php)

PROGRAM:

<html>

<body>

<?php

function word_digit($word)

{

$warr = explode(“;”,$word);

$result=”;

foreach($warr as $value)

{

switch(trim($value))

{

case ‘zero’ :

$result.=’0′;

break;

case ‘one’ :

$result.=’1′;

break;

case ‘two’ :

$result.=’2′;

break;

case ‘three’ :

$result.=’3′;

break;

case ‘four’ :

$result.=’4′;

break;

case ‘five’ :

$result.=’5′;

break;

case ‘six’ :

$result.=’6′;

break;

case ‘seven’ :

$result.=’7′;

break;

case ‘eight’ :

$result.=’8′;

break;

case ‘nine’ :

$result.=’9′;

break;

}

}

return $result;

}

echo word_digit(“zero;three;five;six;eight;one”).”<br>”;

echo word_digit(“seven;zero;one”);

?>

</body>

</html>

OUTPUT:

035681
701

Tags:

Practical

Share Article

Follow Me Written By

Baskaran J

Other Articles

Previous

Practical program exercise 9 PHP String Functions for 12th computer applications

Next

Practical Program Exercise 4 Number conversion for 11th Computer Science

Next
February 22, 2023

Practical Program Exercise 4 Number conversion for 11th Computer Science

Previous
February 17, 2023

Practical program exercise 9 PHP String Functions for 12th computer applications

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

8 − four =

Related Posts

12th CA Board Exam Answer Key Discussion 2024-2025

Baskaran J
March 14, 2025

12th Computer Applications English medium Program Question 2024-2025

Baskaran J
February 23, 2025

12th Computer Applications Practice One marks question 2024-2025

Baskaran J
February 3, 2025

12th Computer Applications English medium Public Exam Important Question 2024-2025

Baskaran J
January 16, 2025

Subscribe to our newsletter and stay updated.

CS Knowledge Opener

CS Knowledge Opener focuses on 11th &12th Computer Science & Computer Applications English Medium & Tamil Medium. Programming Skills and also we are Publishing Study Materials Based on New syllabus introduced by TNSCERT. (TNBOARD).

Quick Links

  • Contact Us
  • About Us
  • Privacy Policy
  • Disclaimer
  • Terms and Conditions
Categories
11th CA English Medium 15
11th CA Tamil Medium 9
11th CS English Medium 21
11th CS Tamil Medium 12
12th CA English Medium 32
12th CA Tamil Medium 8
12th CS English Medium 36
12th CS Tamil Medium 12
Government Exams 36
Notifications 8
Other Subjects 13

Follow Us

Youtube
Facebook
Telegram
CS Knowledge Opener © 2020 - 2025. All Rights Reserved.