0
我得到了兩個文本文件:localhost.txt和host.txt。從TXT文件中刪除類似的條目?
localhost.txt包含:
127.0.0.1:100
127.0.0.1:200
127.0.0.1:300
127.0.0.1:400
127.0.0.1:500
127.0.0.1:600
127.0.0.1:700
127.0.0.1:800
127.0.0.1:(...)
host.txt包含:
172.39.32.1:100
172.39.32.1:200
172.39.32.1:300
172.39.32.1:400
172.39.32.1:500
172.39.32.1:600
172.39.32.1:700
172.39.32.1:800
127.0.0.1:1300
127.0.0.1:1800
172.39.32.1:(...)
(...) 我使用這個腳本
$data = file("localhost.txt");
file_put_contents('host.txt', implode(array_unique($data)));
$fisier = file_get_contents('host.txt');
刪除重複。
我需要一個腳本,它也會刪除相似的行,例如如果localhost.txt中的127.0.0.1:200已經存在於host.txt中,那麼腳本將從host.txt中刪除127.0.0.1中的所有行。
任何想法? :) 謝謝
不知道你在問什麼 - 你想刪除該主機名的所有條目,無論端口? – leftclickben
您的第二行將在讀取之前覆蓋'host.txt'。這是故意的嗎? – Jim
@leftclickben如果來自localhost.txt的127.0.0.1.200行已經存在於host.txt中,那麼我需要從host.txt中刪除所有匹配IP的行127:0.0.1 :) – Kris