The example of this article describes the method of PHP deleting specified lines of txt files and reading txt document data line by line. Share it with everyone for your reference, the details are as follows:
Write values to the txt file in a loop:
$keys = range(1,999); $file = fopen('key_11010000.txt',"w"); foreach($keys as $key){ fwrite($file,"$key\r\n"); } fclose($file); $f1 = fopen('key_11010000.txt','r'); while(!feof($f1)){ $line=fgets($f1); $line = trim($line); $arr[] = $line; } $keys = array_filter($arr); var_dump($keys);
Read the txt document data line by line :
$f1 = fopen('key_11010000.txt','r'); while(!feof($f1)){ $line=fgets($f1); $line = trim($line); $arr[] = $line; } $keys = array_filter($arr); var_dump($keys); die;
I hope this article will be helpful to everyone in PHP programming.
For more related articles on methods of deleting specified lines of txt files and reading txt document data line by line in PHP, please pay attention to the PHP Chinese website!