Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

What is the String?

The string is a collection of char, String contains all data using a single stream. String indexing will be similar to an array, it will start from 0 to strlen()-1, strlen() is the predefined method that will return the total number of char in String.


for example  

$x = "hello";

echo $x;

but indexing will be started from 0 to 4.

echo $x[2];   //l

 
 

in PHP We can declare String using a single quote ' ' and double quote " " both. Single quote string provides pure string value means the variable value will not be rendered. but double quote String " " provide normal string data means the variable value will be rendered.


for example


$x = 'abc ';
echo '$x';   o/p $x
$x= "abc";

echo "$x";     o/p abc



...............................................................................................................................................

Predefine function of String:-

1) strlen() :-  it return String size

   $x = "hello";
echo strlen($x);


2) strrev():-
  it will reverse String


Example of String Function

  $x = "hello";
echo strrev($x);


3) strtoupper():-  Convert string into upper case 

$x = "hello";
echo strtoupper($x).

4) strtolower():-  Convert string into lower case 

$x = "hello";
echo strtolower($x).


5 )str_replace():-  We can replace particular char from String.


$x = "hello";

echo str_replace('h','m' , $x);





5) implode():-  It is used to convert array to String.

$x = array("c","c++","java","php");

echo implode(' ', $x);  //first parameter glue(symbol) and second parameter array




6)  explode():-  It is used to convert String to the array.

$s = "C,C++,JAVA,PHP,.NET,SQL";

$arr = explode(",",$s);

print_r($arr);

   


Complete String based program:-

<?php

$x = "hello";
echo strlen($x)."<br>";
echo strrev($x)."<br>";
echo strtoupper($x)."<br>";
echo strtolower($x)."<br>";
echo str_replace('h','m' , $x);
echo "<br>";
$x = array("c","c++","java","php");

echo implode(' ', $x);

$s = "C,C++,JAVA,PHP,.NET,SQL";

$arr = explode(",",$s);

print_r($arr);

?>


Assignments:-

1)  WAP to check that string is palindrome or not?

2)  WAP  to convert string in the opposite case?

3) WAP to validate mobile?

4)  WAP to validate email?

5)  WAP to validate the name that it should be alphabets?

6)  WAP to validate password that it is weak, strong, or medium?

weak:-  if no special char and length is less then 6
medium:-  less than two special char and length above 6

Strong:- four special char, one upper case, one number length about 8 then 






Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post