PHP Examples - Strings - Substring - String Replacement - Reversal - Trim

PHP Examples - Strings
Substring - String Replacement - Reversal - Trim

Important Functions

1. Stringlength                       -            strlen(string)
2. Stringreversal                    -           strrev(string)
3. Substring                          -            substr(string, starting position, length)
4. Replace Substring              -            str_replace(new_substring, old_substring, string)
5. Trim (Removing Blank Spaces) -     rtrim(string) [ Remove blank space from right]

                                                   -     ltrim(string) [ Remove blank space from left]

Program:
<html >
<head>

<title>PHP Example 4 : STRING</title>
</head>

<body>
<?php
 
 echo "PHP Example 4";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"STRINGS";
 echo"</h1>";
 echo"<br/><li>";
 $string1 = "I LOVE 2K8CSE";
 echo"String: $string1";
 echo"<br/></li>";
 echo"<br/><li>";
 $stringlength= strlen($string1);   //Stringlength
 echo"length: $stringlength";
 echo"<br/></li>";
 echo"<br/><li>";
 $string2 = substr($string1,2,4); //Substring 
 echo" Substring (2,4): $string2";
 echo"<br/></li>";
 echo"<br/><li>";
 $string3= str_replace("I","WE",$string1); //Substring replacement
 echo"String after replacement (I by WE): $string3";
 echo"<br/></li>";
 echo"<br/><li>";
 $string4=strrev($string1);  //String reversal
 echo"String Reversal: $string4";
 echo"<br/></li>";
 echo"<br/><li>";
 $string5 =rtrim("I LOVE       ");    //Removing blank spaces from right of the string
 $string6=ltrim("       2K8CSE.");
 echo $string5.$string6."(removing blank spaces)";
 echo"<br/></li>"; 

 echo "<br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>
Output:







0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...