0% found this document useful (0 votes)
384 views2 pages

Practical No. 7 - String Functions and Array: 1) Write A PHP Program To Demonstrate Different String Functions. Program

The document demonstrates PHP string functions and arrays. It contains code to: 1) Use string functions like str_word_count(), strrev(), str_replace() on the string "Information Technology" and output the results. 2) Create a one dimensional numeric array and string array and output the elements using foreach. 3) Create an associative array to store names and ages and output one element.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
384 views2 pages

Practical No. 7 - String Functions and Array: 1) Write A PHP Program To Demonstrate Different String Functions. Program

The document demonstrates PHP string functions and arrays. It contains code to: 1) Use string functions like str_word_count(), strrev(), str_replace() on the string "Information Technology" and output the results. 2) Create a one dimensional numeric array and string array and output the elements using foreach. 3) Create an associative array to store names and ages and output one element.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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