Jump to content

Memorable word - How to ask for three random letters


bb90

Recommended Posts

Hi,

 

Does anyone know how to create a php file which will ask the user to enter three random characters from their pre-selected word. It would be like with online banking where you have to enter for example letters 2, 4 and 5 from your memorable data.  Any help would be greatley appreciated.

 

Thanks

This should get you started

// Set secret word
$word = 'mysecretword';

// How many letters must they provide
$required_letters = 3;

// Populate array with letters keyed on their position
$letters = array();
while (count($letters) < $required_letters){
    $k = rand(1, strlen($word));
    $letters[$k] = substr($word, $k-1, 1);
}

// Sort if you want them to enter the letters in order
ksort($letters);

// Print array
echo '<pre>';
print_r($letters);
echo '</pre>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.