0% found this document useful (0 votes)
14 views3 pages

Prac 5

The document contains a PHP program that calculates the length of a string and counts the number of words in a string without using string functions. It also includes a demonstration of various built-in string functions such as comparison, repetition, replacement, and case conversion. The provided code snippets illustrate the implementation of these functionalities with example outputs.

Uploaded by

sanketilag60
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)
14 views3 pages

Prac 5

The document contains a PHP program that calculates the length of a string and counts the number of words in a string without using string functions. It also includes a demonstration of various built-in string functions such as comparison, repetition, replacement, and case conversion. The provided code snippets illustrate the implementation of these functionalities with example outputs.

Uploaded by

sanketilag60
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/ 3

Name: Sanket Ilag

Roll No: 63

Practical 5:

A. Write a PHP program to-


Calculate length of string.

Count the number of words in string without using string
functions. B. Write a simple PHP program to demonstrate use of
various built-in string functions

Code: Length of String

<?php
$str = "Welcome to the world of PHP";
$length = strlen($str);
echo "<br> Length of string : " . $length; ?
>
Output:
Code: No. of Words in String

<?php
$str = "Hello world";
$count = 1; // Start from 1 because words = spaces + 1

for ($i = 0; $i < strlen($str); $i++) { // Use `<` instead of `<=` if


($str[$i] == " ") {
$count++;
}
} echo "No. of Words in String = " .
$count; ?>
Output:

Code: All String Functions


<?php
$string = " string HAS its own predifined FUNCTIONS"; $str = "string has its own
predefined functions"; echo "The length of the string is: " . strlen($str); echo "<br>"; echo
"The Result of comparing string is: " . strcmp($string, $str); echo "<br>"; echo "The
Result of the Repeated string is: " . str_repeat($str, 2); echo "<br>"; echo "The Replaced
string is: " . str_replace("predifined", "built-in", $string); echo "<br>"; echo "The Result of
UpperCase is: " . strtoupper($string); echo "<br>"; echo "The Result of LowerCase string
is: " . strtolower($str); echo "<br>"; echo "The Result of Ltrim string is: " . Ltrim($string);
echo
"<br>";
echo "The Result of Rtrim string is: " . Rtrim($string); echo
"<br>"; echo "The Result of WordCount is: " . str_word_count($str);
echo "<br>"; echo "The Result of Possition is: " . strpos($string, "it's");
echo "<br>"; echo "The Result of Possition is: " . ucwords($str); echo
"<br>"; echo "The Result of Reverse is: " . Strrev($str); echo "<br>";
?>

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy