gazsux
01-08-2004, 04:50 PM
Hello,
All I am wanting to do is compare to arrays of strings and filter out one set of strings from the other. Like you may want to filter out a list of staff members names from a list of random people and staff members.
I have a staff text file, it contains:
ione
becs
glitterkat
jibbi
chelseaboy
dany
gazsux
dionysus
I have a list text file, it conatains:
ione
Camel
max
CIACodeName
Disturbed
Explicit
frekka
Frekkeh
gazsux
Habbex
Investigations.
NewsContact
pete
I have the code:
<?php
$file=file("file/list.txt");
$staff=file("file/staff.txt");
$result = array_diff($file, $staff);
foreach($result as $name) {
echo "$name<br>";
}
?>
However, the result I get is:
ione
Camel
max
CIACodeName
Disturbed
Explicit
frekka
Frekkeh
gazsux
Habbex
Investigations.
NewsContact
pete
I cant figure out why! is it to do with \n chars being bought in using file()? How can I make it just list non-staff names. The desired result is:
Camel
max
CIACodeName
Disturbed
Explicit
frekka
Frekkeh
Habbex
Investigations.
NewsContact
pete
I would appreciate any help, cheers
All I am wanting to do is compare to arrays of strings and filter out one set of strings from the other. Like you may want to filter out a list of staff members names from a list of random people and staff members.
I have a staff text file, it contains:
ione
becs
glitterkat
jibbi
chelseaboy
dany
gazsux
dionysus
I have a list text file, it conatains:
ione
Camel
max
CIACodeName
Disturbed
Explicit
frekka
Frekkeh
gazsux
Habbex
Investigations.
NewsContact
pete
I have the code:
<?php
$file=file("file/list.txt");
$staff=file("file/staff.txt");
$result = array_diff($file, $staff);
foreach($result as $name) {
echo "$name<br>";
}
?>
However, the result I get is:
ione
Camel
max
CIACodeName
Disturbed
Explicit
frekka
Frekkeh
gazsux
Habbex
Investigations.
NewsContact
pete
I cant figure out why! is it to do with \n chars being bought in using file()? How can I make it just list non-staff names. The desired result is:
Camel
max
CIACodeName
Disturbed
Explicit
frekka
Frekkeh
Habbex
Investigations.
NewsContact
pete
I would appreciate any help, cheers