PHP implementation of English name full spelling random automatic arranging script _php tutorial

Source: Internet
Author: User
Demand:
1, after the execution of the script, want to go to the students to enter the English name all spell, produce a random number of 01-99 between the number,
The larger the number is to participate in the project practice, the number that has been caught before the next time can not appear the same number.
2, the first input name, the screen output information, and the name and number recorded in the file, the program can not quit
Continue to wait for other students to enter.

Implementation Code (on the command line, not the Web environment):

<?php//Number Library $num = Range (1, 99);//randomly disrupt shuffle ($num); $filename = './user.txt ';//open record file $handle = fopen ($filename, ' w '); Sorted user List $user = array (); while (true) {echo "\r\nenter your name:"; $content = Read (); Exit Script if ($content = = ' exit ') {break  ;}//Remove random value $n = Array_pop ($num);//write File fwrite ($handle, $n. ". $content ." \ r \ n "); $user [$n] = $content; Output to 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 divider-----------------'), fwrite ($handle, "\ r \ n"), Ksort ($user), foreach ($user as $k + = $v) {fwrite ($handle, $k. ". $ V. " \ r \ n ");} Close file fclose ($handle);/*** gets the command line input value * @param string $length * @return string*/function Read ($length = ' 255 ') {if (!isset ($ globals[' Stdinpointer ')) {  $GLOBALS [' Stdinpointer ']=fopen ("Php://stdin", "R"),} $line =fgets ($GLOBALS [' Stdinpointer '], $length); Return trim ($line);}

http://www.bkjia.com/PHPjc/824636.html www.bkjia.com true http://www.bkjia.com/PHPjc/824636.html techarticle requirements: 1, the implementation of the script, want to go to the students to enter the English name of all spelling, produce random number 01-99 between the number, the larger the number will go to participate in project practice, the number of the front has been captured, ...

  • 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.