Thread: Random Text
View Single Post
Old 05-07-2008, 11:36 AM   #2 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

not very pretty, took about 1min to knock up xD so theres most likely to be mistakes or easier ways:
PHP Code:
$words 'I took my dog for a walk';
$wordArr explode(' '$words);
$cnt count($wordArr);
$randNumStor = array();
//generate an array of random numbers
//make sure that no duplicates exist
for($i 0$i <= $cnt$i++)
{
    
$randNum rand(0$cnt);

    while(
in_array($randNum$randNumStor))
    {
        
$randNum rand(0$cnt);
    }
    
$randNumStor[] = $randNum;
}
//display the words based the random numbers in random array
for($j 0$j <= $cnt$j++)
{
    echo 
$wordArr[$randNumStor[$j]], ' ';

hope i havnt got the wrong end of the proverbial stick.

Edit: i think i may have gotten the wrong idea of you probelm, i just quickly scan read it and saw random text, sorry if i have got the wrong idea but still there are some things in that script that you could use
to delete duplicates from an array use array_unique()

for example:
PHP Code:
$words2 'I I took took my my dog dog for for a a walk walk';

$wordArray2 array_unique(explode(' '$words2));

foreach(
$wordArray2 as $word)
{
    echo 
$word ' ';

EDIT: no no it appears i have confused myself twice haha reality and fiction have now become a mad twist in my brain hahahahahahaha.... more coffee needed!
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Orc (05-07-2008)