PHP-implemented script _ PHP Tutorial

Source: Internet
Author: User
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 ,...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.