...

View Full Version : checking flat files



webosb
06-28-2007, 08:34 PM
i'm trying to check a flat file for existing email addresses and I'm using this function:

function emailcheck($emailaddress) {
$str = strtoupper(file_get_contents("preferred.ext"));
if (strpos($str, strtoupper($emailaddress))){
return true;
}else{
return false;
}
}

for some reason, it doesnt seem to find the first email in the flat file, why is it? can someone offer some help?

thanks in advance

Fumigator
06-28-2007, 08:53 PM
It seems like it should work, so you'll have to give us some examples where it doesn't work.

webosb
06-28-2007, 08:57 PM
if the flat file prefered.ext contains:

bob@blah.com
john@blah.com
mike@blah.com

searching for bob@blah.com will result "not found"

Fumigator
06-28-2007, 10:11 PM
By "not found" do you mean it returns false? There's a point to my question, I'm not just picking nits here-- if you check for the success of strpos like you'd normally check for a function's success, i.e.


if (!strpos($a, $b)) {
echo "not found";
}

Then if your string is found in position zero, it will return 0, which is also interpreted as "false" in the "if" statement above, which gives you the impression the string wasn't found.

PHP accounts for this with the triple equals:


if (strpos($a, $b) === false) {
echo "not found";
}


Try that and see if it fixes your problem.

Reference:
http://us2.php.net/manual/en/function.strpos.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum