Problem in handling external text file content from PHP function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • divyac
    New Member
    • Aug 2008
    • 40

    #1

    Problem in handling external text file content from PHP function

    Hi
    I have a text file named email.txt which has the following contents
    test@test.com
    a@x.com
    zooman@deeply.b ored.org
    b@x.com
    guess.me@where. ami.net
    testmore@test.c om

    I want only the domain part of the listed email ids separately. The code which I tried is as follows

    Code:
    <?php
    function getUniqueDomains($list)
    {
    $domains = array();
    foreach($list as $l)
    {
    $arr = explode("@", $l);
    $domains = trim($arr[1]);
    }
    return array_unique($domains);
    }
    $filecontents = file("C:\xampp\htdocs\practice2\file concept\files\email.txt");
    
    $returnArray = getUniqueDomains($filecontents);
    
    foreach($returnArray as $d)
    {
    print "$d, ";
    }
    ?>
    but I am getting some warning message as shown below

    Warning: file(C: mpp\htdocs\prac tice2ile conceptiles\ema il.txt) [function.file]: failed to open stream: Invalid argument in C:\xampp\htdocs \practice2\file concept\file_fu nction.php on line 16

    Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs \practice2\file concept\file_fu nction.php on line 8

    Plz help me out to solve this problem
    Last edited by Markus; Jun 3 '09, 12:54 PM. Reason: Added [code] tags.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the backslashes in the file path are treated as escape characters, so you either have to escape them ("\\") or use single quotation marks ('\')

    \f : form feed
    \e : escape
    \x.. : hexadecimal character

    Comment

    Working...