as

Write a PHP script to demonstrate different String functions.

Write a PHP script to demonstrate different String functions.  

STRING FUNCTIONS

1. Concatenation Operator  2. Strlen( )
3. strpos( )  4. strtoupper( ) 
5. Substr_replace( )  6. Substr( )
7. Substr_count( )



1. Concatenation Operator :-
To concatenate two string variables together, use the dot (.) operator.
Syntax :-
“String Name1"."String Name2";

2. Strlen( ) :-
This function is use to find the length of given string.
Syntax :-
Strlen(“String Name”);

3.strpos( ) :-
The strpos( ) function is used to search for a string or character within a string.
If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE.
Syntax :-
strpos(“string name”, ‘charactor’);

4. strtoupper( ) :-
The strtoupper() function is used to convert string Upper Case.
Syntax :-
strtouppe(“String Name”);

5. Substr_replace( ) :-
This function is use to permits many kinds of string modifications.
Syntax :-
substr_replace(Original string , New String , start[length]);

6. Substr( ) :-
This function is use to find a substring of a string.
Syntax :-
$ans=Substr(string1 , start[length]);

7. Substr_count( ) :-
This function is use to find out how many times a smaller string occurs in large string.
Syntax :-
$ans=substr_count(Big String, Small String);

Code :-


<?php
$string1="Hello Friend ";
$string2="Welcome";
echo "<br>";
echo $string1 . " " . $string2;
echo "<br>";
echo strlen($string1);
echo "<br>";
echo strpos("Hello world!","world"); 
echo "<br>";
echo strtoupper($string1);
echo "<br>";
echo substr_replace($string1, "T",6,1);
echo "<br>";
echo substr($string1,0,5);
echo "<br>";
echo substr_count($string1,"e");
?> 

Output :-

Hello Friend Welcome
13
6
HELLO FRIEND
Hello Triend
Hello
2