You are on page 1of 11

LAB ASSESSMENT – 3

Aman Mukhopadhyay
17BCB0009

1. Date Functions

a. Write a PHP script to get time difference in days and years, months, days, hours, minutes,
seconds between two dates.

Source Code:

Output:

b. Write a PHP script to convert the date to timestamp

Source Code:

Output:
c. Write a PHP script to convert a date from yyyy-mm-dd to dd-mm-yyyy.

Source Code:

Output:

d. Write a PHP script which will display the copyright information in the following format.

Source Code:

Output:

e. Write a PHP script to convert seconds into days, hours, minutes and seconds.
Source Code:

Output:

2. String Functions

a. Write a PHP script to extract the file name and last three characters of a given file path.

Sample String : 'www.example.com/public_html/index.php'

Source Code:

Output:

b. Write a PHP script to replace the first 'the' of the following string with 'That'.

Sample date: 'the quick brown fox jumps over the lazy dog.'
Source Code:

Output:

c. Write a PHP script to remove all leading zeroes from a string.

Original String : '000547023.24'

Source Code:

Output:

d. Write a PHP script to select first 5 words from the following string .

Sample String : 'The quick brown fox jumps over the lazy dog'
Source Code:

Output:

e. Write a PHP script to print letters from 'z’ to ‘a’.

Source Code:

Output:
3. Regular Expression

a. Write a PHP script to remove new lines (characters) from a string Sample strings : "Twinkle,
twinkle, little star,\nHow I wonder what you are.\nUp above the world so high,\nLike a diamond in
the sky."; Expected Output : "Twinkle, twinkle, little star, How I wonder what you are. Up above
the world so high, Like a diamond in the sky."

Source Code:

Output:

b. Write a PHP script to remove all characters from a string except a-z A-Z 0-9 or " ".

Sample string: abcde$ddfd @abcd )der]

Source Code:

Output:
c. Write a PHP script to extract text (within parenthesis) from a string .

Sample strings : 'The quick brown [fox].'

Source Code:

Output:

4. Create a PHP script which displays the capital and state name .Sort the list by the capital of the
state.

Source Code:

Output:
5. $x = array(1, 2, 3, 4, 5); Delete an element from the above PHP array. After deleting the
element, integer keys must be normalized. Sample Output : array(5) { [0]=> int(1) [1]=> int(2)
[2]=> int(3) [3]=> int(4) [4]=> int(5) } array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3 ) [3]=>
int(5) }

Source Code:

Output:
6. Write a PHP script to calculate and display average temperature, five lowest and highest
temperatures. Recorded temperatures : 78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 75, 76, 73, 68,
62, 73, 72, 65, 74, 62, 62, 65, 64, 68, 73, 75, 79, 73 Expected Output : Average Temperature is :
70.6 List of seven lowest temperatures : 60, 62, 63, 63, 64, List of seven highest temperatures : 76,
78, 79, 81, 85

Source Code:

7. Write a PHP program to merge (by index) the following two arrays. Sample arrays : $array1 =
array(array(77, 87), array(23, 45)); $array2 = array("w3resource", "com");

Source Code:
Output:

8. Write a PHP program to remove duplicate values from an array which contains only strings or
only integers.

Source Code:
Output:

You might also like