switch statement PHP random number generation, page jump, file reading and writing, file renaming, switch statement

WBOY
Release: 2016-07-29 08:40:35
Original
1238 people have browsed it

复制代码 代码如下:


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;
}
?>


刚做的一个项目中的部分代码,包含了php中随机数的产生、页面跳转、件读写、文件重命名、switch语句。
特发表出来,希望能对php学习者能够有所帮助。

以上就介绍了switch语句 php 随机数的产生、页面跳转、件读写、文件重命名、switch语句,包括了switch语句方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!