1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Scrambling Letters in A Variable

Discussion in 'PHP' started by qdsouza, Sep 5, 2005.

  1. #1
    Is there a simple way to scramble letters in a variable?

    If I have something like:

    $word='animal'

    and I get something like the:

    $word1='minala"

    Thanks
     
    qdsouza, Sep 5, 2005 IP
  2. LGRComp

    LGRComp Well-Known Member

    Messages:
    516
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    195
    #2
    str_shuffle() should do what you want.

    See: http://ca.php.net/manual/en/function.str-shuffle.php
     
    LGRComp, Sep 5, 2005 IP
    sarahk likes this.
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #3
    probably not.

    but this will do it
    <?PHP
    /**
     * @return string
     * @param string $word
     * @desc scrambles the word given.
    */
    function scramble($word)
    {
    	$newword = array();
    	for($i = 0; $i < strlen($word); $i++)
    	{
    		$num = rand(0, 100);
    		$newword[$num] = substr($str, $i, 1);
    	}
    	ksort($newword);
    	$output = implode('', $newword);
    	return $output;
    }
    
    echo scramble('animal');
    ?>
    Code (markup):
     
    sarahk, Sep 5, 2005 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #4
    good find LGRComp

    I didn't even check to see if there was a function!
     
    sarahk, Sep 5, 2005 IP
  5. qdsouza

    qdsouza Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for the help that did it :)
     
    qdsouza, Sep 5, 2005 IP