Monday, 16 November 2015

3_String SHUFFLE Function in PHP

2) String SHUFFLE Function


$string1 =”HarshidaDParmar “;
$string2= str_shuffle($string1);
echo $string2;


when you run this program it will randomly shuffle the string character.


Very useful to generate the random password.


But also you can see that it will generate the long random string we want little bit less length for random number … so what will we do?


We are going to use the subsrt() “SUB STING FUNCTION ”


$string1 =”0123456789abcdefghijklmnopqrstuvwxyz “;
$string2= str_shuffle($string1);
$half1=substr($string2,0,7);
echo $half1;


0 Shows the starting position in the 2nd parameter, 7 Last length


Means we want the RAMDOM PASSWORD LENGTH IS IN BETWEEN 0 TO 7.


3) String Reverse Function


$string1=”HARSHIDA PARMAR “;
$string2=strrev($string1);
echo $string2;

Reverse function will reverse the string passed in the parameter.



No comments:

Post a Comment