PHP implements a script with full names and random numbers. Requirement: 1. after the script is executed, the students who want to enter the English name and enter the full spelling to generate a number between 0-99 random numbers. the larger the number is, they will join the project practice,
Requirements:
1. after the script is executed, the students who want to enter a full English name and generate a number ranging from 0 to 99,
The larger the number, the larger the number will be used in the project practice. the same number cannot appear next time.
2. after the first input name, the screen outputs information and records the name and number in the file. the program cannot exit.
Wait for other students to enter.
Implementation code(Run the command line instead of the WEB environment ):
<? Php // number Library $ num = range (1, 99); // randomly shuffle ($ num); $ filename = '. /user.txt '; // open the record file $ handle = fopen ($ filename, 'w'); // list of sorted users $ user = array (); while (true) {echo "\ r \ nEnter your name:"; $ content = read (); // exit the script if ($ content = 'delete') {break ;} // Retrieve the random value $ n = array_pop ($ num); // write the file fwrite ($ handle, $ n. ''. $ content. "\ r \ n"); $ user [$ n] = $ content; // output to the console echo "Hi $ content, your number is" . $ N. "\ r \ n";} // close control to input stream fclose ($ GLOBALS ['stdinpointer ']); fwrite ($ handle, "\ r \ n "); fwrite ($ handle, '---------------- gorgeous separation line -----------------'); fwrite ($ handle, "\ r \ n"); ksort ($ user ); foreach ($ user as $ k =>$ v) {fwrite ($ handle, $ k. ''. $ v. "\ r \ n");} // close the file fclose ($ handle ); /*** obtain the input value of the command line * @ param string $ length * @ return string */function read ($ length = '20140901') {if (! Isset ($ GLOBALS ['stdinpointer ']) {$ GLOBALS ['stdinpointer'] = fopen ("php: // stdin", "r ");} $ line = fgets ($ GLOBALS ['stdinpointer '], $ length); return trim ($ line );}
Example 1: After the script is executed, enter a full English name and generate a number ranging from 0 to 99. the larger the number, join the project practice ,...