php:比較兩個txt檔案,格式如下,分別取出a.txt有的b.txt沒有的,b.txt有的a.txt沒有的及兩個都有的

來源:互聯網
上載者:User

標籤:blog   ar   for   檔案   div   on   log   as   res   

<?php/*比較兩個txt檔案,格式如下,分別取出a.txt有的b.txt沒有的,b.txt有的a.txt沒有的及兩個都有的 * a.txt: * A * B * C * D * b.txt * A * B * M * N * result: * only_a.txt * C * D * only_b.txt * M * N * public_a_b.txt * A * B */$curr_file_name = dirname(__FILE__);if (file_exists($curr_file_name . ‘\a.txt‘)) {    $array_a = explode("\r\n", trim(file_get_contents(‘a.txt‘)));}if (file_exists($curr_file_name . ‘\b.txt‘)) {    $array_b = explode("\r\n", trim(file_get_contents(‘b.txt‘)));}if($array_a) {    foreach ($array_a as $value) {        if (!in_array($value, $array_b)) {            $only_a[] = $value;        }    }    file_put_contents("only_a.txt", implode("\r\n", $only_a));}if($array_b) {    $public_a_b = array();    foreach ($array_b as $value) {        if (!in_array($value, $array_a)) {            $only_b[] = $value;        } else {            $public_a_b[] = $value;        }    }    file_put_contents("only_b.txt", implode("\r\n", $only_b));    file_put_contents("public_a_b.txt", implode("\r\n", $public_a_b));}?>

  

php:比較兩個txt檔案,格式如下,分別取出a.txt有的b.txt沒有的,b.txt有的a.txt沒有的及兩個都有的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.