0% found this document useful (0 votes)
39 views

Assignment For Improvement-IWP

The document provides PHP code snippets to complete an assignment involving string manipulation functions. It includes code to: 1. Display the months of the year using associative arrays. 2. Use built-in string functions to: a) Display unique characters in a string b) Convert a string to an array using explode() c) Replace a substring ignoring case using str_ireplace() d) Count the occurrences of a substring using substr_count() e) Randomly shuffle the characters in a string using str_shuffle()

Uploaded by

Kush Choudhary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Assignment For Improvement-IWP

The document provides PHP code snippets to complete an assignment involving string manipulation functions. It includes code to: 1. Display the months of the year using associative arrays. 2. Use built-in string functions to: a) Display unique characters in a string b) Convert a string to an array using explode() c) Replace a substring ignoring case using str_ireplace() d) Count the occurrences of a substring using substr_count() e) Randomly shuffle the characters in a string using str_shuffle()

Uploaded by

Kush Choudhary
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment for Improvement-IWP

18BCE0557 KUSHAL

1. Display the months of the year using associative arrays in the following format “January is the
First month” and so on for all the months.

<?php
$months​ = ​array​(​"First"​=>​"January"​, ​"Second"​=>​"February"​,
"Third"​=>​"March"​, ​"Fourth"​=>​"April"​, ​"Fifth"​=> ​"May"​, ​"Sixth"​=>​"June"​,
"Seventh"​=> ​"July"​, "
​ Eighth"​=>​"August"​, ​"Ninth"​=>​"September"​,
"Tenth"​=>​"October"​, "​ Eleventh"​=>​"November"​, ​"Twelfth"​=>​"December"​);

​ <center>"​;
echo​ "
echo​ "​ </br></br></br></br>"​;
foreach​(​$months​ as ​$order​ => ​$month​) {
​echo​ ​"<b>"​. ​$month​ .​" is the "​. ​$order​ .​" month </b>"​;
​echo​ ​"</br></br>"​;
}
echo​ ​"</center>"​;

?>

2. Use the inbuilt string functions

a) Display only the unique characters present in the string “I like PHP and MySQL!”

b) Convert the given string into an array. $str=”Red#Blue#Yellow#Green”

c) In the string “Hello Class! It is an interesting class”, replace class with “world” irrespective of the
case.

d) Count the number of times “over” is occurs in the string “Over the hills and over the mountains..
over and over again they went”.

e) Randomly shuffle the letters in the string

a)

<?php

$string1​ = ​"I like PHP and MySQL!"​;


echo​ ​count_chars​(​$string1​, ​3​)

?>
b)

<?php
$str​=​"Red#Blue#Yellow#Green"​;
print_r​ (​explode​(​"#"​, ​$str​));
?>

c)

<?php
$str1​ = ​"Hello Class! It is an interesting class"​;
echo​ ​str_ireplace​(​"class"​,​"world"​,​$str1​);
?>

d)
<?php
$str​ = ​"Over the hills and over the mountains.. over and over again they
went"​;

// Considering it as not case sensitive

echo​ ​substr_count​(​strtolower​(​$str​), ​"over"​)

?>

e)
<?php

​ Doing DA before many days of deadline is so much pleasurable, wish


$str​ = "
I knew this earlier!"​;

echo​ ​"Original String: "​. ​$str​;

echo​ ​"</br></br>"​;

echo​ ​"Shuffled String: "​. ​str_shuffle​(​$str​);

?>

You might also like