PHP头条
热点:

php打印文本中随机行内容


 

此段代码可以打印文本中的随机行数,例如,一个文本中有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学习博客” 博客

www.phpzy.comtrue/phprm/20018.htmlTechArticlephp打印文本中随机行内容 此段代码可以打印文本中的随机行数,例如,一个文本中有1W行,我需要随机取出500行。 1. $file=txt; 2. $data=file_get_contents($file); 3. $arr=explode(\n,$data); 4. $count=cou...

相关文章

    暂无相关文章

PHP之友评论

今天推荐