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

    Join Date
    Jul 2013
    Posts
    5
    Rep Power
    0

    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:
     $i=0;
     
    open file 1 
     open file 2
    if
        { 
    any string in line one==any string in line 2}
        
    $i++

    else 
    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 Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,572
    Rep Power
    595
    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