Jump to content

File Handling


divyac

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

"{$var1}{$var2}{string}"

is known to be slightly faster than

$var1 . $var2 . 'string'

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...