You are on page 1of 5

Samarth Polytechnic Belhe

DEPARTMENT OF COMPUTER ENGINEERING

Subject : Web Based application development using PHP. Subject code : 22619

Semester : 6th Course : Computer Engineering

Name of Subject Teacher: Prof.Kshirsagar. S. B Laboratory No:L001B

Name of Student:Gadekar Rohit Pravin Enrollment no: 1909920050

Date of Performance : / /2022 Date of Submission : / /2022

Experiment No: 5

Title of Experiment: 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.

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.

2.0 String concept:


It is sequence of characters enclosed within pair of single quotation marks or double quotation mark.

3.0 New Concepts:


String Functions:
1. str_word_count(): count the number of words in the string
2. strlen(): return the length of string
3. strrev(): reverse a string
4. strops(): returns position of first occurrence of string
5. str_replace(): replaces some characters in a string
6. ucwords(): convert first character each word into uppercase
7. strtoupper(): convert string to uppercase letters
8. strtolower(): convert string to lowercase letters
9. strcmp(): compare two strings

4.0 Learing Ojectives:

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:

Srno Equipment Name with broad specification Practical

1 Hardware : any computer system (preferably i3 or i5) All

2 Operating System: Windows/Linux All

3 Any Database tool such as MYSQL,MariaDB 15,16

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:

Without Using String Function:

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

You might also like