php打印文本中随机行内容
来源:岁月联盟
时间:2011-10-31
此段代码可以打印文本中的随机行数,例如,一个文本中有1W行,我需要随机取出500行。
1. $file="txt";
2. $data=file_get_contents($file);
3. $arr=explode("/n",$data);
4. $count=count($arr)-1;
5. $num=500;
6. for($i=1;$i<=$num;$i++){
7. $n=rand(0,$count);
8. echo $arr[$n]."/n";
9. }
本文出自 “mcshell学习博客” 博客
上一篇:php中session机制探究