Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Practical no.

7 – String functions and Array

1) Write a PHP program to demonstrate different string functions.

Program:

<?php

$s1="Information Technology";

echo"Given String:".$s1;

echo"<br>Number of words in given string:".str_word_count($s1);

echo"<br>Reverse of a given string:".strrev($s1);

echo"<br>Replace Technology by Management:".str_replace("Technology","Management",$s1);

echo"<br>String in uppercase:".strtoupper($s1);

echo"<br>String in lowercase:".strtolower($s1);

echo"<br>Length of a string:".strlen($s1);

echo("<br>");

echo strcmp("Hello","Hello");

echo("<br>");

echo strcasecmp("Hello world:","Hello world");

echo("<br>");

?>

Output:

PRANIL D. 18302E0056
2) Write a PHP program to create one dimensional array.

Program:

<?php

$numarr=array(29,34,23,56,12);

echo "Number array:-";

foreach($numarr as $a)

echo $a.",";

$colors=array("red", "green", "blue", "yellow");

echo"<br> String array :-";

foreach($colors as $a)

echo $a." , ";

#ASSOCIATIVE_ARRAYS

$age= array("Mahesh"=>"15", "Naresh "=>"17","Suresh"=>"23");

echo"Mahesh is " .$age["Mahesh"]."Years old.";

?>

Output:

PRANIL D. 18302E0056

You might also like