Help please ! How to remove lines ? ASAP plz
Moderator: General Moderators
-
illusion123
- Forum Newbie
- Posts: 4
- Joined: Sat Dec 09, 2006 1:13 pm
Help please ! How to remove lines ? ASAP plz
Hello.
I have 2 files.
In first file I have lines with email addresses of subscribers.
In second file I have lines with emails who want to unsubscribe.
How to remove from the first file lines that I have in the second (unsubscribe) file ?
Please tell me how to make this with PHP or linux shell.
Thank you very much !
I have 2 files.
In first file I have lines with email addresses of subscribers.
In second file I have lines with emails who want to unsubscribe.
How to remove from the first file lines that I have in the second (unsubscribe) file ?
Please tell me how to make this with PHP or linux shell.
Thank you very much !
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Do it by hand?
It can be done in PHP, but the only way I can think of uses in a nested for loop which would be very slow.
pseudo code:
It can be done in PHP, but the only way I can think of uses
Code: Select all
str_replace()pseudo code:
Code: Select all
foreach line in unsubscribe list as linex
foreach line in subscribe list as liney
if linex == liney
delete liney
end if
end foreach
end foreach- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
1. use file() on both of the files
2. loop through your second file using foreach()
3. use in_array() against the first array of the looped value to double check they are in first file
4. unset() the value of the looped array against the first file
5. rewrite the first file using fopen() and fwrite()
Enjoy.
jayshields: No need for nested loops
2. loop through your second file using foreach()
3. use in_array() against the first array of the looped value to double check they are in first file
4. unset() the value of the looped array against the first file
5. rewrite the first file using fopen() and fwrite()
Enjoy.
jayshields: No need for nested loops
-
illusion123
- Forum Newbie
- Posts: 4
- Joined: Sat Dec 09, 2006 1:13 pm
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
illusion123
- Forum Newbie
- Posts: 4
- Joined: Sat Dec 09, 2006 1:13 pm
Jcart | Please use
Don`t work =(
Run the following in a new file and tell us the results please.
Jcart | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
<?phpCode: Select all
$subscribers = file('subscribers.txt');
$unsubscribers = file('un.txt');
$sortedsubscribers = "sortedsubscribers.txt";
foreach ($subscribers as &$value) {
foreach ($unsubscribers as &$unvalue) {
if ($value = $unvalue) then ($value="")
$fh = fopen($sortedsubscribers, 'a') or die("Error!!");
fwrite($fh, "$value\n");
fclose($fh);
}
}
>Run the following in a new file and tell us the results please.
Jcart | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Try using the comparison operator == instead of the assignment operator =
Also, try using curly braces to encapsulate the statements you want to be associated with your if(), like this:
Also, try using curly braces to encapsulate the statements you want to be associated with your if(), like this:
Code: Select all
if(/*condition*/)
{
//statement 1
//statement 2
}