Professional Documents
Culture Documents
Subject : Web Based application development using PHP. Subject code : 22619
Experiment No: 5
Theory:
1.0 Title:
a) Write a PHP program to calculate length of string and count number of words in a string without
using string function.
b) Write a PHP program to demonstrate the use of built in string function.
Intellectual Skills:
1. To understand the concept of string
2. To understand the use of functions of string
Motor Skills:
1. Ability to use string functions to solve problems
2. Ability to use PHP web servers.
5.0 Apparatus:
Strlen():
Program: -
<?php
$str="ROHIT";
$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="Sarthak";
$result=strrev($str); echo
$result;
?>
Output:
Str_replace():
Program:
<?php
$str="Sarthak";
$result=str_replace("Sarthak", "Jagtap","Sarthak"); echo
$result;
?>
Output:
Strcmp(): Program:
<?php
$str1="Sarthak";
$str2="SarthakJagtap";
$result=strcmp($str1, $str2); echo
$result;
?>
Output:
Program:
<?php
$var="Jagtap Sarthak Santosh ";
$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:
Process Product Total (25 Dated Sign Of
Grade and Related Related M) Teacher
Dated Signature of (15M) (10M)
Teacher