Samarth Polytechnic Belhe: Department of Computer Engineering
Samarth Polytechnic Belhe: Department of Computer Engineering
Subject : Web Based application development using PHP. Subject code : 22619
Experiment No: 5
Theory:
Title:
a) Write a PHP program to calculate length of string and count number of words in astring
without using stringfunction.
b) Write a PHP program to demonstrate the use of built in stringfunction.
Learing Ojectives:
IntellectualSkills:
1. To understand the concept ofstring
2. To understand the use of functions ofstring
Motor Skills:
1. Ability to use string functions to solveproblems
2. Ability to use PHP webservers.
5.0 Apparatus:
Strlen():
Program: -
<?php
$str="Siddhesh";
$result=strlen($str);
echo$result;
?>
Output:-
String_word_count():
Program:-
<?php
$str="samarth polytechnic belhe";
$result=str_word_count($str);
echo $result;
?>
Output:
Strrev():
Program:-
<?php
$str="Siddhesh";
$result=strrev($str);
echo$result;
?>
Output:
Str_replace():
Program:
<?php
$str="Siddhesh";
$result=str_replace("Siddhesh","Phapale","Siddhesh");
echo$result;
?>
Output:
Strcmp():
Program:
<?php
$str1="Siddhesh";
$str2="SiddheshPhapale";
$result=strcmp($str1, $str2);
echo $result;
?>
Output:
Without Using String Function:
Program:
<?php
$var="Phapale Siddhesh Ramdas";
$wordcount=0;
for($i=0; $i<strlen($var)-1; $i++)
{
if($var[$i]==' '&&ctype_alpha($var[$i+1])&&($i>0))
{
$wordcount++;
}
}
$wordcount++;
print_r("Total Word Count is $wordcount");
?>
Output: