I'm trying to pull a random number of keywords from a file...and I just can get it. Basically what I have is a list of keywords, on per line, in a text file, and I need to pull out x number of those keywords on the fly. I don't have access to a database, hence the text file. So what I have so far is: <? $f1 = file("keywords.txt"); $max = "10"; $min = "5"; $item = array_rand ($f1); $toshow = rand($max,$min); $i = 1; while ($i < $toshow){ echo $item[$i]; $i = $i+1; }; ?> Code (markup): But obviously this isn't working or I wouldn't be here... Any help? Thanks in advance, Mike
Is it possible that you could give me an example...I really seem to be struggling with this. thanks in advance, Mike
Displays between 2 and 6 random lines from test.txt: $keyword_array = file('test.txt'); $min = 2; $max = 6; $num_keywords = rand($min, $max); $rand_keyword_keys = array_rand($keyword_array, $num_keywords); foreach ($rand_keyword_keys as $key => $value) { echo $keyword_array[$value] . '<br />'; } PHP: