Copy codeThe Code is as follows:
<? Php
Num = rand (1, 5 );
Witch ($ num ){
Case 1:
$ Fp1 = fopen ("f1.dat", 'R ');
$ Oname = fgets ($ fp1 );
$ Nname = date ("YmdHis ");
Rename ($ oname, $ nname );
Fclose ($ fp1 );
Unlink ("f1.dat ");
$ Fp1 = fopen ("f1.dat", 'w ');
Fwrite ($ fp1, $ nname );
Fclose ($ fp1 );
Header ("Location:". $ nname. "/1.html ");
Exit;
Break;
Case 2:
$ Fp2 = fopen ("f2.dat", 'R ');
$ Oname = fgets ($ fp2 );
$ Nname = date ("YmdHis ");
Rename ($ oname, $ nname );
Fclose ($ fp2 );
Unlink ("f2.dat ");
$ Fp2 = fopen ("f2.dat", 'w ');
Fwrite
($ Fp2, $ nname );
Fclose ($ fp2 );
Header ("Location:". $ nname. "/2.html ");
Exit;
Break;
Case 3:
$ Fp3 = fopen
("F3.dat", 'R ');
$ Oname = fgets ($ fp3 );
$ Nname = date ("YmdHis ");
Rename ($ oname, $ nname );
Fclose ($ fp3 );
Unlink
("F3.dat ");
$ Fp3 = fopen ("f3.dat", 'w ');
Fwrite ($ fp3, $ nname );
Fclose ($ fp3 );
Header ("Location:". $ nname. "/3.html ");
Exit;
Break;
Case 4:
$ Fp4 = fopen ("f4.dat", 'R ');
$ Oname = fgets ($ fp4 );
$ Nname = date ("YmdHis ");
Rename
($ Oname, $ nname );
Fclose ($ fp4 );
Unlink ("f4.dat ");
$ Fp4 = fopen ("f4.dat", 'w ');
Fwrite ($ fp4, $ nname );
Fclose ($ fp4 );
Header ("Location:". $ nname. "/4.html ");
Exit;
Break;
Case 5:
$ Fp5 = fopen ("f5.dat", 'R ');
$ Oname = fgets ($ fp5 );
$ Nname = date ("YmdHis ");
Rename ($ oname, $ nname );
Fclose ($ fp5 );
Unlink ("f5.dat ");
$ Fp5 = fopen ("f5.dat", 'w ');
Fwrite
($ Fp5, $ nname );
Fclose ($ fp5 );
Header ("Location:". $ nname. "/5.html ");
Exit;
Break;
Default:
Break;
}
?>
Part of the Code in the just-created project includes the generation of random numbers in php, page Jump, read/write, file rename, and switch statements.
I hope it will be helpful to php learners.