我有一個包含域和IPS看起來像這樣比較,從文件中讀取PHP領域
aaa.bbb.com 8.8.8.8
bbb.com 2.2.2.2
...
一個txt文件 ...
..
如何更換bbb.com到3.3.3.3,但不改變aaa.bbb.com?
這是我的功能的一部分,但根本不工作。
我從文件
閱讀它一行行,我得到了匹配的記錄後,搜索匹配域第一部分,將其刪除。
第二部分我寫了一個新的一行。
$filename = "record.txt";
$lines = file($filename);
foreach($lines as $line)
if(!strstr($line, "bbb.com") //I think here is the problem core
$out .= $line;
$f = fopen($filename, "w");
fwrite($f, $out);
fclose($f);
$myFile = "record.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "bbb.com\n 3.3.3.3\n";
fwrite($fh, $stringData);
fclose($fh);
後,我執行我的代碼,都aaa.bbb.com和bbb.com被刪除了,我怎麼能解決這個問題呢?
我試過「parse_url」,但「parse_url」只用「http://」前綴而不是域解析url。
如果你正在寫這樣的'$ StringData是= 「bbb.com \ n 3.3.3.3 \ n」 個數據;'這將有2個每條記錄都有一行:一個是域名,另一個是IP地址。那是對的嗎? –
對不起,這應該是一個錯誤,它應該像「bbb.com \ t 3.3.3.3 \ n」選項卡而不是換行符 – tommyhsu