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

PHP prints random lines of text_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:46:45
Original
966 people have browsed it

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 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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template