PHP Delete txt file specify line and read txt document data by line method

Source: Internet
Author: User
This article describes the PHP delete txt file to specify the line and read the TXT document data by line method. Share to everyone for your reference, as follows:

To loop write values to the TXT file:

$keys = Range (1,999), $file = fopen (' Key_11010000.txt ', "w"), foreach ($keys as $key) {  fwrite ($file, "$key \ r \ n");} Fclose ($file); $f 1 = fopen (' key_11010000.txt ', ' R '), while (!feof ($f 1)) {  $line =fgets ($f 1);  $line = Trim ($line);  $arr [] = $line;} $keys = Array_filter ($arr); Var_dump ($keys);

Read TXT document data by line:

$f 1 = fopen (' key_11010000.txt ', ' R '), while (!feof ($f 1)) {  $line =fgets ($f 1);  $line = Trim ($line);  $arr [] = $line;} $keys = Array_filter ($arr); Var_dump ($keys);d ie;

I hope this article is helpful to you in PHP programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.