NYCPHP Meetup

NYPHP.org

[nycphp-talk] Warning: 1 is not a valid File-Handle resource - HELP!

Brian brian at preston-campbell.com
Sun Dec 29 09:21:44 EST 2002


Not to add any further confusion if you are simply wish to fix what you
have, but you could read the contents of your textfile into an array
with file()

$nicks = file("nicknames.txt");

// You then use rtrim() to remove any unwanted whitespace,newlines, or
carriage returns at the end of each item.

foreach ($nicks as $nick) {
$trimmed_nick = rtrim($nick);
echo "$trimmed_nick<br>";
}

On Sun, 2002-12-29 at 04:10, Phil Powell wrote:
> Ok, I am a bad coder. :(  I can't figure this out at all:
> 
>    $fileID = fopen("nicknames.txt", 'r');
>     $stuff = fread($fileID, filesize("nicknames.txt")); fclose($fileID);
>     if (strlen($stuff) > 0) $priorNickNewLine = "\
"; 
>     $nicks = explode("\
", $stuff);
> 
> The last line produces the Warning.. why?  I am trying to read contents from nicknames.txt and split according to the newline character so that each nickname is an array element.
> 
> What did I do wrong? :(
> 
> Phil
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 
> 





More information about the talk mailing list