Difference between revisions of "Spring 2020: PHP Programming Lab"
Jump to navigation
Jump to search
(Created page with "PHP Prgramming Lab") |
|||
(169 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | PHP | + | * '''Instructions''' |
+ | *# Please be on time to avoid the attendance penalty. | ||
+ | *# Turn off(shutdown) your assigned computer after finishing your work (or before you leave the lab). | ||
+ | *# Please arrange the chairs in proper place while leaving the lab. | ||
+ | *# Please put your phone in silent mode. | ||
+ | |||
+ | == '''Lab 1: Getting Started''' ( week of 6th/7th January 2020 ) == | ||
+ | * Brief introduction to PHP [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/Lab01.pdf ['''Download''']] | ||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. | ||
+ | ! Program | ||
+ | ! Lab Exercise No. | ||
+ | ! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%" | WAP to print first n even numbers | ||
+ | | style="width: 15%" | Practice Set No. 13 | ||
+ | | | ||
+ | |- | ||
+ | | 2 || WAP to find sum of first n odd numbers || Practice Set No. 14 || | ||
+ | |- | ||
+ | | 3 || WAP to check whether the given number is prime or not || Practice Set No. 12 || | ||
+ | |- | ||
+ | | 4 || WAP to print the following pattern using nested for loop:<br> | ||
+ | *<br> | ||
+ | * *<br> | ||
+ | * * *<br> | ||
+ | * * * * | ||
+ | || Practice Set No. 17 || | ||
+ | |- | ||
+ | | 5 || WAP to sort an array using built in PHP function || Lab Exercise No. 2 || | ||
+ | |} | ||
+ | |||
+ | == '''Lab 2: '''( week of 13th/14th January 2020 ) == | ||
+ | * Arrays, Strings and Functions in PHP [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/Lab02.pdf ['''Download''']] | ||
+ | |||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Create a PHP page using functions for comparing three integers and print the largest number (function with arguments, function without arguments, function returning value) | ||
+ | | style="width: 15%"| Practice Set No. 10 | ||
+ | | | ||
+ | |- | ||
+ | | 2 | ||
+ | | Write a function to calculate the factorial of a number(non-negative integer). The function accepts the number as an argument | ||
+ | | Practice Set No. 11 | ||
+ | | | ||
+ | |- | ||
+ | | 3 || Write a PHP script that checks whether a passed string is palindrome of not? (A Palindrome is word, phrase, or sequence that reads the same backward as forward. For example: mom, dad, madam, Step on no pets, nurses run || Practice Set No. 15 || | ||
+ | |- | ||
+ | | 4 || $color = array("white","green","red") <br> | ||
+ | Write a PHP script which will display the colors in the following way: <br> | ||
+ | Output:<br> | ||
+ | white, green, red,<br> | ||
+ | * green | ||
+ | * red | ||
+ | * white | ||
+ | || Lab Exercise No. 5 || | ||
+ | |- | ||
+ | | 5 || Write a PHP script which will perform string manipulations using in-built functions. || Practice Set L2 || | ||
+ | |} | ||
+ | |||
+ | == '''Lab 3: '''( week of 20th/21st January 2020 ) == | ||
+ | * Introduction to PHP Form Handling [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/Lab03.pdf ['''Download''']] | ||
+ | |||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Create a form which collects data like Name, Roll Number, Course, Address. Using a submit button send it for processing to a PHP file named "mydata.php". Use HTTP POST method to send the form-data and finally display the submitted data. | ||
+ | | style="width: 15%"| Practice Set No. L3 | ||
+ | | | ||
+ | |- | ||
+ | | 2 | ||
+ | | Create the same form as Q.NO. 1, and submit using HTTP GET method. | ||
+ | | Practice Set No. L3 (2) | ||
+ | | | ||
+ | |- | ||
+ | | 3 || Create a PHP page which accepts string from user. After submission that page displays the reverse of provided string. | ||
+ | || Lab Exercise No. 1 || | ||
+ | |- | ||
+ | | 4 || Write a PHP program to print Fibonacci series using recursion. || Practice Set No. 16 || | ||
+ | |} | ||
+ | |||
+ | == '''Lab 4: '''( week of 27th/28th January 2020 ) == | ||
+ | * To get select data [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/lab4Select.txt ['''Download''']] | ||
+ | * To get radio data [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/lab4Radio.txt ['''Download''']] | ||
+ | * To get checkbox data [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/lab4Checkbox.txt ['''Download''']] | ||
+ | * Sample Form for Q. NO. 1 [http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/lab4Form.png ['''Form''']][http://mkbhandari.com/mkwiki/data/spring2020/PHPLab/lab4FormProcess.txt ['''Code''']] | ||
+ | |||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Create a form with elements/controls like text, textarea, select, radio button, checkbox, etc. Read the form data, submit it on the same page and display the submitted data. | ||
+ | | style="width: 15%"| Practice Set No. L4 | ||
+ | | | ||
+ | |- | ||
+ | | 2 | ||
+ | | Create the same form as Q.NO. 1, read the form data in another form named formProcess.php using GET/POST method. | ||
+ | | Practice Set No. L4 (2) | ||
+ | | | ||
+ | |- | ||
+ | | 3 || Using switch case and dropdown list display a “Hello” message depending on the language selected in drop down list. | ||
+ | || Lab Exercise No. 6 || | ||
+ | |- | ||
+ | | 4 || Create a simple "birthday countdown" script, the script will count the number of days between current day and birth day. || Lab Exercise No. 4 || | ||
+ | |} | ||
+ | |||
+ | == '''Lab 5: '''( week of 03rd/04th February 2020 ) == | ||
+ | * Read PHP Date and Time from [https://www.w3schools.com/php/php_date.asp w3schools] | ||
+ | * Read PHP Regular Expressions [https://www.geeksforgeeks.org/php-regular-expressions/ geeksforgeeks] | ||
+ | |||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Use date function to perform following: | ||
+ | * Display date in the different formats(mm-dd-yyyy, mm.dd.yyyy, mm:dd:yyyy, yyyy/mm/dd, etc) | ||
+ | * Display time in the different format (12-hour, 24-hour) | ||
+ | * Display your birthday using mktime() function | ||
+ | * Create a Date from a String With strtotime() | ||
+ | * Display dates for the next 10 PHP Lab | ||
+ | | style="width: 15%"| Practice Set No. L5 | ||
+ | | | ||
+ | |- | ||
+ | | 2 | ||
+ | | Create a simple "birthday countdown" script, the script will count the number of days between current day and birth day '''using PHP date and time functions'''. | ||
+ | | Lab Exercise No. 4 | ||
+ | | | ||
+ | |- | ||
+ | | 3 | ||
+ | | Write a menu driven PHP script that: <br> | ||
+ | a. Removes the whitespaces from a string. | ||
+ | * Sample string: ‘The quick ” ” brown fox’ | ||
+ | * Expected Output: Thequick'”‘brownfox [ '''Hint:''' str_replace(''find,replace,string,count'') ]<br> | ||
+ | b. Checks if a string contains another string. (using built in php functions) <br> | ||
+ | c. Checks if a string is all lower case. (using regex) <br> | ||
+ | d. Replace the first 'the' of the following string with 'That'. | ||
+ | * Sample: 'the quick brown fox jumps over the lazy dog.' | ||
+ | * Expected Result: That quick brown fox jumps over the lazy dog. | ||
+ | | Lab Exercise No. 3 | ||
+ | | Regular Expressions Cheatsheet [https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285][https://www.bounteous.com/files/uploads/Regular-Expressions-Google-Analytics_2019.pdf] | ||
+ | |} | ||
+ | |||
+ | == '''Lab 6: '''( week of 10th/11th February 2020 ) == | ||
+ | * Complete all the previous assignments(1-5) | ||
+ | * Revisit MySQL concepts from [https://www3.ntu.edu.sg/home/ehchua/programming/sql/MySQL_Beginner.html NTU Tutorial] | ||
+ | |||
+ | == '''Lab 7: '''( week of 17th/18th February 2020 ) == | ||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Create a MySQL Database named '''myDB''' Using MySQLi/PDO | ||
+ | | style="width: 15%"| Practice Set No. L7 | ||
+ | | Creating a Database [https://www.w3schools.com/php/php_mysql_create.asp] | ||
+ | |- | ||
+ | | 2 | ||
+ | | Create a MySQL Table name '''myUsers''' Using MySQLi/PDO in '''myDB''' database with following attributes: | ||
+ | * username | ||
+ | * password | ||
+ | use appropriate data types, size, and constraints | ||
+ | | Practice Set No. L7(2) | ||
+ | | Creating a table [https://www.w3schools.com/php/php_mysql_create_table.asp] | ||
+ | |- | ||
+ | | 3 | ||
+ | | Insert five records in '''myUsers''' table Using MySQLi/PDO (duplicate atleast 1 username in the record) | ||
+ | | Practice Set No. L7(3) | ||
+ | | Adding data into a table [https://www.w3schools.com/php/php_mysql_insert.asp] | ||
+ | |- | ||
+ | | 4 | ||
+ | | Create a '''login page''' having '''user name''' and '''password'''. On clicking submit, a welcome message should be displayed if the user is already registered (i.e. name is present in the database) otherwise error message should be displayed. | ||
+ | | Lab Exercise No. 7 | ||
+ | | Select data from a table [https://www.w3schools.com/php/php_mysql_select_where.asp ] | ||
+ | |||
+ | |} | ||
+ | |||
+ | == '''Lab 8: '''( week of 24th/25th February 2020 ) == | ||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Write a PHP program to check that the entered '''email id''' of the form '''username@domainname''' is valid and the '''domain name''' is present in the database table. | ||
+ | | style="width: 15%"| Lab Exercise No. 8 | ||
+ | | use regular expression to test for valid '''email id''' | ||
+ | |} | ||
+ | |||
+ | == '''Lab 9/Lab10: '''( week of 02nd/03rd March) == | ||
+ | * Complete all the previous assignments(1-8) | ||
+ | |||
+ | == '''Final Lab''' == | ||
+ | |||
+ | {| class="wikitable" style="text-align: left; width: 100%"; | ||
+ | |- | ||
+ | ! Q. NO. !! Program !! Lab Exercise No. !! Remarks | ||
+ | |- | ||
+ | | style="width: 8%" | 1 | ||
+ | | style="width: 60%"| Create a database table containing the marks of students in three subjects along with their roll number and name. Create a PHP page to display the mark sheet of the student along with the grade obtained. | ||
+ | | style="width: 15%"| Lab Exercise No. 9 | ||
+ | | Select data from database and put result in HTML table | ||
+ | [https://tryphp.w3schools.com/showphpfile.php?filename=demo_db_select_oo_table] | ||
+ | |} |
Latest revision as of 03:32, 24 May 2020
- Instructions
- Please be on time to avoid the attendance penalty.
- Turn off(shutdown) your assigned computer after finishing your work (or before you leave the lab).
- Please arrange the chairs in proper place while leaving the lab.
- Please put your phone in silent mode.
Contents
- 1 Lab 1: Getting Started ( week of 6th/7th January 2020 )
- 2 Lab 2: ( week of 13th/14th January 2020 )
- 3 Lab 3: ( week of 20th/21st January 2020 )
- 4 Lab 4: ( week of 27th/28th January 2020 )
- 5 Lab 5: ( week of 03rd/04th February 2020 )
- 6 Lab 6: ( week of 10th/11th February 2020 )
- 7 Lab 7: ( week of 17th/18th February 2020 )
- 8 Lab 8: ( week of 24th/25th February 2020 )
- 9 Lab 9/Lab10: ( week of 02nd/03rd March)
- 10 Final Lab
Lab 1: Getting Started ( week of 6th/7th January 2020 )
- Brief introduction to PHP [Download]
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | WAP to print first n even numbers | Practice Set No. 13 | |
2 | WAP to find sum of first n odd numbers | Practice Set No. 14 | |
3 | WAP to check whether the given number is prime or not | Practice Set No. 12 | |
4 | WAP to print the following pattern using nested for loop:* |
Practice Set No. 17 | |
5 | WAP to sort an array using built in PHP function | Lab Exercise No. 2 |
Lab 2: ( week of 13th/14th January 2020 )
- Arrays, Strings and Functions in PHP [Download]
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Create a PHP page using functions for comparing three integers and print the largest number (function with arguments, function without arguments, function returning value) | Practice Set No. 10 | |
2 | Write a function to calculate the factorial of a number(non-negative integer). The function accepts the number as an argument | Practice Set No. 11 | |
3 | Write a PHP script that checks whether a passed string is palindrome of not? (A Palindrome is word, phrase, or sequence that reads the same backward as forward. For example: mom, dad, madam, Step on no pets, nurses run | Practice Set No. 15 | |
4 | $color = array("white","green","red") Write a PHP script which will display the colors in the following way:
|
Lab Exercise No. 5 | |
5 | Write a PHP script which will perform string manipulations using in-built functions. | Practice Set L2 |
Lab 3: ( week of 20th/21st January 2020 )
- Introduction to PHP Form Handling [Download]
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Create a form which collects data like Name, Roll Number, Course, Address. Using a submit button send it for processing to a PHP file named "mydata.php". Use HTTP POST method to send the form-data and finally display the submitted data. | Practice Set No. L3 | |
2 | Create the same form as Q.NO. 1, and submit using HTTP GET method. | Practice Set No. L3 (2) | |
3 | Create a PHP page which accepts string from user. After submission that page displays the reverse of provided string. | Lab Exercise No. 1 | |
4 | Write a PHP program to print Fibonacci series using recursion. | Practice Set No. 16 |
Lab 4: ( week of 27th/28th January 2020 )
- To get select data [Download]
- To get radio data [Download]
- To get checkbox data [Download]
- Sample Form for Q. NO. 1 [Form][Code]
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Create a form with elements/controls like text, textarea, select, radio button, checkbox, etc. Read the form data, submit it on the same page and display the submitted data. | Practice Set No. L4 | |
2 | Create the same form as Q.NO. 1, read the form data in another form named formProcess.php using GET/POST method. | Practice Set No. L4 (2) | |
3 | Using switch case and dropdown list display a “Hello” message depending on the language selected in drop down list. | Lab Exercise No. 6 | |
4 | Create a simple "birthday countdown" script, the script will count the number of days between current day and birth day. | Lab Exercise No. 4 |
Lab 5: ( week of 03rd/04th February 2020 )
- Read PHP Date and Time from w3schools
- Read PHP Regular Expressions geeksforgeeks
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Use date function to perform following:
|
Practice Set No. L5 | |
2 | Create a simple "birthday countdown" script, the script will count the number of days between current day and birth day using PHP date and time functions. | Lab Exercise No. 4 | |
3 | Write a menu driven PHP script that: a. Removes the whitespaces from a string.
b. Checks if a string contains another string. (using built in php functions)
|
Lab Exercise No. 3 | Regular Expressions Cheatsheet [1][2] |
Lab 6: ( week of 10th/11th February 2020 )
- Complete all the previous assignments(1-5)
- Revisit MySQL concepts from NTU Tutorial
Lab 7: ( week of 17th/18th February 2020 )
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Create a MySQL Database named myDB Using MySQLi/PDO | Practice Set No. L7 | Creating a Database [3] |
2 | Create a MySQL Table name myUsers Using MySQLi/PDO in myDB database with following attributes:
use appropriate data types, size, and constraints |
Practice Set No. L7(2) | Creating a table [4] |
3 | Insert five records in myUsers table Using MySQLi/PDO (duplicate atleast 1 username in the record) | Practice Set No. L7(3) | Adding data into a table [5] |
4 | Create a login page having user name and password. On clicking submit, a welcome message should be displayed if the user is already registered (i.e. name is present in the database) otherwise error message should be displayed. | Lab Exercise No. 7 | Select data from a table [6] |
Lab 8: ( week of 24th/25th February 2020 )
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Write a PHP program to check that the entered email id of the form username@domainname is valid and the domain name is present in the database table. | Lab Exercise No. 8 | use regular expression to test for valid email id |
Lab 9/Lab10: ( week of 02nd/03rd March)
- Complete all the previous assignments(1-8)
Final Lab
Q. NO. | Program | Lab Exercise No. | Remarks |
---|---|---|---|
1 | Create a database table containing the marks of students in three subjects along with their roll number and name. Create a PHP page to display the mark sheet of the student along with the grade obtained. | Lab Exercise No. 9 | Select data from database and put result in HTML table |