This is data2.txt file:
=======================
user1    web1    2002-03-25 14:43:17
user1    web2    2002-03-25 14:43:20
user2    web2    2002-03-25 14:50:02
user2    web2    2002-03-25 14:55:00
user1    web1    2002-03-25 14:45:00
user3    web2    2002-03-26 16:20:00
user3    web3    2002-03-26 16:21:17
user4    web1    2002-03-26 18:45:23
user4    web3    2002-03-26 18:50:00
user4    web1    2002-03-26 19:01:00
user4    web2    2002-03-26 19:20:20


======================
      PROBLEM #1      
======================
We want to print out a matrix of users and webs - how many times 
an user visited a website.


======================
      SOLUTION #1      
======================

<?php

$fd 
fopen ("data2.txt""r");  // open file for reading
$website = array();

while (!
feof ($fd)) {
  
$fileline fgets($fd4096);

  
// Replace line breaks at the end /r=DOS /n=Unix
  
$fileline str_replace("\n","",$fileline);
  
$fileline str_replace("\r","",$fileline);

  
$line explode("\t"$fileline);
  
$data[$line[0]][$line[1]]++;

  if ( !
in_array$line[1], $website ) ) { $website[] = $line[1];}
}

print 
'userID';
for(
$i=0;$i<count($website);$i++) {
  print 
' '.$website[$i];
}
print 
"<br>\n";

foreach( 
$data as $user=>$sites ) {
  print 
$user.': ';
  for(
$i=0;$i<count($website);$i++) {
    print 
$sites[$website[$i]]?$sites[$website[$i]]:0;
    print 
" ";
  }
  print 
"<br>\n";
}

?>

The result (from this program) is:
==================================
userID web1 web2 web3
user1: 2 1 0 
user2: 0 2 0 
user3: 0 1 1 
user4: 2 1 1 

The result is a matrix which tells me how many times has a single user been in 
the website.


======================
      PROBLEM #2      
======================
A) a matrix where in cells are counts of users which has been on the both websites.
Example:
    [web1]    [web2] 
[web1]    [a]    [b] 
[web2]    [c]    [d] 

a = number of users which were on web1
b = number of users which were on web1 AND web2
c = b 
d = number of users which were on web2 

THE RESULT SHOULD BE:
=====================
    web1    web2    web3
web1    2    2    1
web2    2    4    2
web3    1    2    2


( web1: user1 (2x), user2 (0x), user3 (0x), user4 (2x) )
( web2: user1 (1x), user2 (2x), user3 (1x), user4 (1x) )
( web3: user1 (0x), user2 (0x), user3 (1x), user4 (1x) )

======================
      SOLUTION #2      (PARTLY SOLUTION, NOT OK!)
======================

<?php

$fd 
fopen ("data2.txt""r");  // open file for reading
$website = array();

while (!
feof ($fd)) {
  
$fileline fgets($fd4096);

  
// Replace line breaks at the end /r=DOS /n=Unix
  
$fileline str_replace("\n","",$fileline);
  
$fileline str_replace("\r","",$fileline);

  
$line explode("\t"$fileline);
  
$data[$line[0]][$line[1]]++;

  if ( !
in_array$line[1], $website ) ) { $website[] = $line[1];}
}

foreach( 
$data as $user=>$sites ) {
  for(
$i=0;$i<count($website);$i++) {
    if ( 
$sites[$website[$i]] ) {
      for(
$j=0;$j<count($website);$j++) {
        if ( !
$sites[$website[$j]] ) continue;
        
$mat_a[$website[$i]][$website[$j]]++;
      }
    }
  }
}

print 
'<pre>';print_r$mat_a );print '</pre>';

?>


The result (from this program) is:
==================================

Array
(
    [web1] => Array
        (
            [web1] => 2
            [web2] => 2
            [web3] => 1
        )

    [web2] => Array
        (
            [web1] => 2
            [web2] => 4
            [web3] => 2
        )

    [web3] => Array
        (
            [web2] => 2
            [web3] => 2
            [web1] => 1
        )

)





======================
      PROBLEM #3      
======================

Another matrix which gives a number of "travels" FROM one website TO another
For instance - we see, that users were moving the following way:

user1: web1 -> web2 -> web1
user2: web2 -> web2  (RELOAD!)
user3: web2 -> web3
user4: web1 -> web3 -> web1 -> web2

So we have the following relations: 
web1 -> web2 (happens 2-times) 
web1 -> web3 (happens 1-times) 
web2 -> web1 (happens 1-times) 
web2 -> web2 (happens 2-times)
web2 -> web3 (happens 1-times) 
web3 -> web1 (happens 1-times) 
web3 -> web2 (happens 0-times)

We can make a matrix then:
    [web1]    [web2]    [web3]
[web1]    [0]    [2]    [1]
[web2]    [1]    [2]    [1]
[web3]    [1]    [d]    [0]

As we can see, this matrix is not symetrical, while previous is.