Hi, i would like to, using php, randomly select a word from the current page, which i have already managed to get into a string. I would like to use php to randomly choose any of the words, the full word.
If you have the words in an array you can do: $words = array("word1","word2","word3"); $random = rand(0, count($words)-1); echo $words[$random]; PHP: To get the words into an array from a string use the explode() function on space characters or something..
And you may also need to use array_diff() function to filter out filler words like 'and', 'or', 'be', 'may be', etc. if you need.
Thanks, but it dosn't seem to be working for me: I have made this, using google define: http://obolynx.com/developments/import.php?word=whom and i would like to select each word on the page in turn and have it hyperlinked, this is what i have so far codewise: for($i = 0, $size = sizeof($matches[0]); $i < $size; ++$i) { // assuming the string is called "someString" $words = explode(" ", $matches[0][$i]); $index = rand(0, count($words)-1); $choice = $words[$index]; $href = '<a href="import.php?word='; $href .= $choice; $href .= '">'; $href .= $choice; $href .= '</a>'; echo $href; echo $choice; $randomWord = array_rand($words); echo $randomWord; } Code (markup): Thanks