1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Rep Power

    Comparing txt files or using an array

    I have two text files. Both contain a list of urls. I am wondering is it possible to compare the two files so that when two strings/urls in each file are identical a counter will increase, giving me the number of similar files in the two text documents. Is it possible to do this or do i have to reload the urls into an array to compare them??

    PHP Code:
    open file 1 
     open file 2
    any string in line one==any string in line 2}

    keep reading 
    Otherwise, does anyone have any ideas of how i would go about putting each text file into a separate array(or multidimensional array) on one page, comparing the elements in both and incrementing the count? Each individual array element has to be compared to every other element in the other array.

    Any thoughts?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Rep Power
    Reading the files into arrays then using array_intersect is a near trivial solution. The count() of the resulting array is what you are looking for.

    Comments on this post

    • oneshot2shots agrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo