Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts

    checking flat files

    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

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It seems like it should work, so you'll have to give us some examples where it doesn't work.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    28
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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"

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    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.
    PHP Code:
    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:
    PHP Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •