i have two configuration files which i need to compare using PHP. I can convert these config files to text files. So now i have to just compare two text files which has headings, sub-headings and so on. plz if any one can help me
(1)first text file---
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)text file
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*
!
I think it would be better to save these files as xml or yml then you could parse them into objects and see if each individual setting is the same.
http://php.net/manual/en/function.yaml-parse.php
But to compare two text files you could hash them can check if the results match each other.
if(hash_file('md5', 'example.txt') == hash_file('md5', 'example2.txt')){
//do something
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.