I'm kind of lost on this one - I need to modify 2 files based on user input:
$data_array = file($data_file );
$counter_array = file($counter_f ile);
// There is a line-for-line relationship between the data and counter files
//for example, if the 3rd line in the counter file is deleted,
//so also must the 3rd line of the data file be deleted.
// Each line of the data_file has 4 items:
//date|ip_address |user_id|url
for ( $i=0; $i < count($data_arr ay); $i++ )
$data_line = fgets($data_arr ay); //look at each line in data_array
$data = explode("|",$da ta_line);
if ( $data[1] = $ip ) //$ip is user input
{
array_pop($data _array, $data_line);
array_pop($coun ter_array[$i];
//not sure array_pop is correct function here - the manual says this
//will pop element from the bottom of the array, but I need
//to delete this particular element from the middle of the array.
//What is the best way to do this?
}
The goal is to create 2 new files. If the original files look like this:
[data_file]
3/4/04|20.123.112.2 1|grebos|http://www.asc.com
6/5/04|183.40.99.14 |boris|http://www.asc.com
7/16/04|133.73.115.2 9|grebos|http://www.asc.com
[counter file]
2345
1356
5466
and the user selected to remove IP 183.40.99.14, then the new files should
look like this:
[data_file]
3/4/04|20.123.112.2 1|grebos|http://www.asc.com
7/16/04|133.73.115.2 9|grebos|http://www.asc.com
[counter file]
2345
5466
I'm still kind of green when it comes to working with arrays... any help is
appreciated... Thanks.
$data_array = file($data_file );
$counter_array = file($counter_f ile);
// There is a line-for-line relationship between the data and counter files
//for example, if the 3rd line in the counter file is deleted,
//so also must the 3rd line of the data file be deleted.
// Each line of the data_file has 4 items:
//date|ip_address |user_id|url
for ( $i=0; $i < count($data_arr ay); $i++ )
$data_line = fgets($data_arr ay); //look at each line in data_array
$data = explode("|",$da ta_line);
if ( $data[1] = $ip ) //$ip is user input
{
array_pop($data _array, $data_line);
array_pop($coun ter_array[$i];
//not sure array_pop is correct function here - the manual says this
//will pop element from the bottom of the array, but I need
//to delete this particular element from the middle of the array.
//What is the best way to do this?
}
The goal is to create 2 new files. If the original files look like this:
[data_file]
3/4/04|20.123.112.2 1|grebos|http://www.asc.com
6/5/04|183.40.99.14 |boris|http://www.asc.com
7/16/04|133.73.115.2 9|grebos|http://www.asc.com
[counter file]
2345
1356
5466
and the user selected to remove IP 183.40.99.14, then the new files should
look like this:
[data_file]
3/4/04|20.123.112.2 1|grebos|http://www.asc.com
7/16/04|133.73.115.2 9|grebos|http://www.asc.com
[counter file]
2345
5466
I'm still kind of green when it comes to working with arrays... any help is
appreciated... Thanks.
Comment