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.