0% found this document useful (0 votes)
4 views

php_prac_5

The document contains PHP programs that demonstrate various string functions including strlen, str_word_count, strrev, strpos, str_replace, strcmp, strtolower, strtoupper, and ucwords. It also includes a program to calculate the length of a string and another to count the number of words in a string without using built-in string functions. Each program outputs the results of the respective string operations.

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

php_prac_5

The document contains PHP programs that demonstrate various string functions including strlen, str_word_count, strrev, strpos, str_replace, strcmp, strtolower, strtoupper, and ucwords. It also includes a program to calculate the length of a string and another to count the number of words in a string without using built-in string functions. Each program outputs the results of the respective string operations.

Uploaded by

saeedarwatkar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical No.

5
1. Write a program to develop string functions.
<?php

$str="hello php";

$arr=array("blue","red","pink");

echo "strlen function: ";

echo strlen("Hello World");

echo "<br>";

echo "str_word_count function: ";

echo str_word_count("hello world");

echo "<br>";

echo "strrev function: ";

echo strrev("hello world");

echo "<br>";

echo "strpos function: ";

echo strpos($str,"php");

echo "<br>";

echo "strreplace function: ";

print_r (str_replace("red","yellow",$arr));

echo "<br>";

echo "strcmp function: ";

echo strcmp("hello world","hello world");

echo "<br>";

echo "strtolower function: ";

echo strtolower("HELLO");

echo "<br>";

echo "strtoupper function: ";


echo strtoupper("hello");

echo "<br>";

echo "ucwords function: ";

echo ucwords("welcome to php programming");

?>

Output

2. Write a program to calculate length of a string.

<?php

$str="hello php";

$arr=array("blue","red","pink");

echo "strlen function: ";

echo strlen("Hello World");

?>

Output:
3. Write a program to count the number of words in string without using string functions
<?php

$str="Hello to PHP Programming";

$words= explode(" ", $str);

echo "Number of words: ".count($words);

?>

Output:

You might also like