Showing posts with label PHP str shuffle Function Tutorial. Show all posts
Showing posts with label PHP str shuffle Function Tutorial. Show all posts

Monday, April 30, 2012

PHP str shuffle Function Tutorial


str shuffle Function
Syntax:
str_shuffle(string)

The str_shuffle() function randomly shuffles all the characters of a string.
The str_shuffle() function is mainly used for to to generate a random password or produce random characters for CAPTCHA validation image.
Each time this function executes and it will randomly re-shuffle the string.
Example: 1
        <?php
        $string = 'This is a test';
        $x=str_shuffle($string);
        echo $x;
        ?>
Output
aih istT sest

Random character generator.
Example: 2
        <?php
        $string = 'abcdefghijklmnopqrstwxyz0123456789';
        $x=str_shuffle($string);
        $y = substr($x,0, 5);
        echo $y;
        ?>
Output
g1c3w

Example: 3
        <?php
       $string = 'abcdefghijklmnopqrstwxyz0123456789';
       $x=str_shuffle($string);
       $y = substr($x,0, strlen($string)/2);
       echo $y;
        ?>
Output
57zo04xp3hykcl1ei 

See a password generator program below the link:
Password Generator Program