1

我有两个配置文件需要使用 PHP 进行比较。我可以将这些配置文件转换为文本文件。所以现在我必须比较两个具有标题、子标题等的文本文件。PLZ如果有人可以帮助我

(1)第一个文本文件---

Building configuration...

Current configuration : 458572 bytes
!

!
upgrade fpd auto

version 12.2

!
hostname IVY-DC-CORESTK-1
!
boot-start-marker
!

*interface fastethernet0/0

     ip address 1.1.1.2 255.255.255.0

     real

        inservice*
!
!
!
!

(2)文本文件

Building configuration...

Current configuration : 458572 bytes

!
!

upgrade fpd auto

version 12.2
!

hostname **IVY-DC-cpucpu**

!

boot-start-marker

!

 *interface fastethernet0/0

      ip address 1.1.1.1 255.255.255.0

      real

         inservice*
!
4

1 回答 1

0

我认为将这些文件保存为 xml 或 yml 会更好,然后您可以将它们解析为对象并查看每个单独的设置是否相同。

http://php.net/manual/en/function.yaml-parse.php

但是要比较两个文本文件,您可以对它们进行哈希处理,以检查结果是否相互匹配。

if(hash_file('md5', 'example.txt') == hash_file('md5', 'example2.txt')){
     //do something
}

http://php.net/manual/en/function.hash-file.php

于 2013-03-07T09:48:04.423 回答