M
M
Michael Compass2020-03-30 04:09:08
PHP
Michael Compass, 2020-03-30 04:09:08

Why PHP script does not remove all duplicate lines?

There is a script (running with cron):

<?php
$file= file ('sbor_proxy_s_dybliami.txt'); // файл на входе
sort ($file); // сортируем по алфавиту
$file = array_unique($file); // убираем повторы
foreach($file as $val){
$end .= $val ;
}
$out=fopen('gotovo_vse_sellery_bezdybley.txt','w'); // файл на выходе
fwrite($out,$end);
fclose($out);


This script must read the file sbor_proxy_s_dybliami.txt ,
then check it for duplicates,
then delete exactly the duplicate line, but leaving the original line,
then the script writes the received data without duplicates to the file

gotovo_vse_sellery_bezdybley.txt In the file gotovo_vse_sellery_bezdybley.txt I see duplicate lines, what should I change in the script so that the script deletes duplicates as I need?

I am attaching the files below:
input file: sbor_proxy_s_dybliami.txt

2.87.116.68:8080
79.130.38.71:4145
79.131.163.165:4145
85.73.26.116:8080
62.103.25.184:35798
94.65.255.158:4145
79.130.222.252:4145
178.147.5.112:4145
79.106.108.102:4145
79.106.165.238:39983
185.120.38.103:4145
80.90.88.147:32850
79.106.108.110:57960
79.106.165.30:50194
79.106.34.26:4145
79.106.35.197:1080
80.78.70.9:4145
185.188.216.93:4145
91.187.116.232:53526
185.85.152.241:58083
95.107.199.90:4145
37.26.85.98:4145
185.33.34.76:51604
185.85.152.243:1080
178.132.218.126:4145
80.78.73.58:4145
77.247.88.10:41757
91.187.116.232:53526
37.26.85.98:4145
79.106.115.105:4145
79.106.108.102:4145
79.106.165.238:39983
185.120.38.103:4145
80.90.88.147:32850
79.106.165.30:50194
79.106.108.110:57960
80.78.70.9:4145
79.106.35.197:1080
79.106.34.26:4145
185.188.216.93:4145
46.190.47.253:4145
85.74.89.216:4145
2.87.116.68:8080
79.130.38.71:4145
79.131.163.165:4145
85.73.26.116:8080
62.103.25.184:35798
94.65.255.158:4145


output file, it should not contain duplicates, but for some reason they are: gotovo_vse_sellery_bezdybley.txt

178.132.218.126:4145
178.147.5.112:4145
185.120.38.103:4145
185.188.216.93:4145
185.188.216.93:4145
185.33.34.76:51604
185.85.152.241:58083
185.85.152.243:1080
2.87.116.68:8080
37.26.85.98:4145
46.190.47.253:4145
62.103.25.184:35798
77.247.88.10:41757
79.106.108.102:4145
79.106.108.110:57960
79.106.115.105:4145
79.106.165.238:39983
79.106.165.30:50194
79.106.34.26:4145
79.106.35.197:1080
79.130.222.252:4145
79.130.38.71:4145
79.131.163.165:4145
80.78.70.9:4145
80.78.73.58:4145
80.90.88.147:32850
85.73.26.116:8080
85.74.89.216:4145
91.187.116.232:53526
94.65.255.158:414594.65.255.158:4145
95.107.199.90:4145

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-03-30
@nokimaro

I think this will solve the problem

sort ($file); // сортируем по алфавиту
$file = array_map('trim', $file); // <---------------
$file = array_unique($file); // убираем повторы

Since there are no problems in the above code, if this is the entire code
https://3v4l.org/ukTns
We see that out of 48 ip with duplicates, 30 are unique

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question