Home > php教程 > php手册 > body text

php打印文本中随机行内容

WBOY
Release: 2016-06-13 10:45:35
Original
1258 people have browsed it

 

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

7.    $n=rand(0,$count);

8.    echo $arr[$n]."\n";

9.    }

  

 

 

本文出自 “mcshell学习博客” 博客

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template