/    Sign up×
Community /Pin to ProfileBookmark

How to work function fgets?

I like to parse values from variable with WHILE code like:

[code=php]

while (!feof($variable)) {
$myvalues= fgets($variable, 4096);
echo $myvalues;
}
[/code]

Values are within variable ($variable) like.
15.03.2010 04:54:34 7 mydefinedvalues

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 08.2010 — Is $variable a file handle from the fopen() function (which is what fgets() is expecting)?
Copy linkTweet thisAlerts:
@ehimeDec 08.2010 — Try:

[code=php]
if ($var = fopen('the.txt', 'r')) do {

echo fgets($var, 4096);

} while (!feof($var));
fclose($var);
[/code]


This will at least avoid infinity loops while cycling
Copy linkTweet thisAlerts:
@toplisekauthorDec 09.2010 — Seems path with wrong value. Is this path issue:

Warning: fopen(/myfolder/terms/myfile.txt) [function.fopen]: failed to open stream

Warning: fclose(): supplied argument is not a valid stream resource in...
×

Success!

Help @toplisek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...