Jump to content

File Handling


Recommended Posts

HiI have a text file named email.txt which has the following contentstest@test.coma@x.comzooman@deeply.bored.orgb@x.comguess.me@where.ami.nettestmore@test.comI want only the domain part of the listed email ids separately. The code which I tried is as follows<?phpfunction 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 belowWarning: file(C: mpp\htdocs\practice2ile conceptiles\email.txt) [function.file]: failed to open stream: Invalid argument in C:\xampp\htdocs\practice2\file concept\file_function.php on line 16Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\practice2\file concept\file_function.php on line 8Plz help me out to solve this problem

Link to comment
Share on other sites

It seems your double quotes are messing things up. Perhaps \xa is a reference to a character? Anyhow... the solution is simple - use single quotes instead:

$filecontents = file('C:\xampp\htdocs\practice2\file concept\files\email.txt');

Personally, for similar reasons, I never use double quotes unless I want to concatenate variables or output a variable within another variable. When I do, I use double quotes instead of "." as


is known to be slightly faster than

$var1 . $var2 . 'string'

Edited by boen_robot
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...