doujiao1949
doujiao1949
2018-08-15 00:55

使用file_get_content更新txt文件

已采纳

I have the following code:

$fisier = file_get_contents('urlproxy'); // Read the file with the proxy list
$linii = explode("
", $fisier); // Get each proxy
$fisier = fopen("bune.txt", "a"); // Here we will write the good ones

I need every time I run the script it rewrites the txt file only with the new proxy.

Can someone help me?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • duandu1915 duandu1915 3年前

    You are using fopen with 'a' mode. According to the PHP documentation:

    'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. In this mode, fseek() has no effect, writes are always appended.

    So, you need to use 'w' mode. Like this:

    $fisier = fopen("bune.txt", "w"); 
    
    点赞 评论 复制链接分享

为你推荐