可以在写入文件前,先读取已有的内容,然后判断是否已经存在相同的链接地址,如果存在则不写入,否则写入。

修改后的代码如下:

phpwhiletrue $url = httpaplbttqxyzsjpngapitextphp; $text = file_get_contents$url; $filename = sptxt; $handle = fopen$filename a+; $contents = fread$handle filesize$filename; ifstrpos