SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Arrow How to ramdom a string in php?

    Hi guys

    let say i have a name called: "john"

    I want to random the letters of john.

    how? or what command in php to able to do this?

    thank you.

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Enthusiast primozc's Avatar
    Join Date
    Nov 2008
    Location
    Slovenia, EU
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First you have to split it using str_split, then you can shuffle the array.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by primozc View Post
    First you have to split it using str_split, then you can shuffle the array.
    Or just use str_shuffle...
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    911
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    i know it is easy.

    But i'm was rushing, it's really a BIG help from you guys when time is counting...

    Thank you again...

  6. #6
    SitePoint Member
    Join Date
    Jun 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    function random_string( )
    {
    $character_set_array = array( );
    $character_set_array[ ] = array( 'count' => 7, 'characters' => 'abcdefghijklmnopqrstuvwxyz' );
    $character_set_array[ ] = array( 'count' => 1, 'characters' => '0123456789' );
    $temp_array = array( );
    foreach ( $character_set_array as $character_set )
    {
    for ( $i = 0; $i < $character_set[ 'count' ]; $i++ )
    {
    $temp_array[ ] = $character_set[ 'characters' ][ rand( 0, strlen( $character_set[ 'characters' ] ) - 1 ) ];
    }
    }
    shuffle( $temp_array );
    return implode( '', $temp_array );


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •