Home  >  Article  >  Backend Development  >  PHP prints random lines of text_PHP tutorial

PHP prints random lines of text_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:46:45895browse

This code can print a random number of lines in the text. For example, there are 1W lines in a text and I need to randomly take out 500 lines.

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. }

This article comes from the "mcshell learning blog" blog

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478551.htmlTechArticleThis code can print a random number of lines in the text, for example, there are 1W lines in a text, I need random Take out 500 rows. 1. $file=txt; 2. $data=file_get_contents($file); 3. $arr=explod...
Statement:
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