Switch statement PHP random number generation, page jump, piece read/write, file Rename, switch statement

Source: Internet
Author: User
Copy CodeThe code is as follows:


num = rand (1,5);
Witch ($num) {
Case 1:
$FP 1=fopen ("F1.dat", ' R ');
$oname = fgets ($fp 1);
$nname = Date ("Ymdhis");
Rename ($oname, $nname);
Fclose ($fp 1);
Unlink ("F1.dat");
$FP 1=fopen ("F1.dat", ' W ');
Fwrite ($fp 1, $nname);
Fclose ($fp 1);
Header ("Location:". $nname. " /1.html ");
Exit
Break
Case 2:
$FP 2=fopen ("F2.dat", ' R ');
$oname = Fgets ($fp 2);
$nname = Date ("Ymdhis");
Rename ($oname, $nname);
Fclose ($fp 2);
Unlink ("F2.dat");
$FP 2=fopen ("F2.dat", ' W ');
Fwrite
($fp 2, $nname);
Fclose ($fp 2);
Header ("Location:". $nname. " /2.html ");
Exit
Break
Case 3:
$FP 3=fopen
("F3.dat", ' R ');
$oname = fgets ($fp 3);
$nname = Date ("Ymdhis");
Rename ($oname, $nname);
Fclose ($fp 3);
Unlink
("F3.dat");
$FP 3=fopen ("F3.dat", ' W ');
Fwrite ($fp 3, $nname);
Fclose ($fp 3);
Header ("Location:". $nname. " /3.html ");
Exit
Break
Case 4:
$FP 4=fopen ("F4.dat", ' R ');
$oname = fgets ($fp 4);
$nname = Date ("Ymdhis");
Rename
($oname, $nname);
Fclose ($fp 4);
Unlink ("F4.dat");
$FP 4=fopen ("F4.dat", ' W ');
Fwrite ($fp 4, $nname);
Fclose ($fp 4);
Header ("Location:". $nname. " /4.html ");
Exit
Break
Case 5:
$FP 5=fopen ("F5.dat", ' R ');
$oname = fgets ($fp 5);
$nname = Date ("Ymdhis");
Rename ($oname, $nname);
Fclose ($fp 5);
Unlink ("F5.dat");
$FP 5=fopen ("F5.dat", ' W ');
Fwrite
($fp 5, $nname);
Fclose ($fp 5);
Header ("Location:". $nname. " /5.html ");
Exit
Break
Default
Break
}
?>


A part of the code in a project that has just been done includes the generation of random numbers in PHP, page jumps, piece reads and writes, file renaming, and switch statements.
Published, hoping to be helpful to PHP learners.

The above describes the switch statement PHP random number generation, page jumps, pieces read and write, file renaming, switch statement, including the switch statement aspects of the content, I hope that the PHP tutorial interested friends have helped.

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