/    Sign up×
Community /Pin to ProfileBookmark

if true go to next line

Hi,

Im looking for a function that allows me to get to the nest line of a file that is read if something is true eg…

[code=php]
$fp = fopen($filename, “r”); //Open the server log
$content = fread($fp, filesize($filename)); // Read the server log
$content = explode(“n”, $content); // explode into array
$content = array_reverse($content ); // reverse the array

$a = 2;
if ($a <3 ‘then goto next line of file’){
then do some stuff in here}

else{}

[/code]

Can anyone help with this please??

Thanks. Eon201

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@LuboxNov 08.2007 — fgets() perhaps, if I understand your question? Read about it in the manual here.

Example 623. Reading a file line by line:

[code=php]
<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
echo $buffer;
}
fclose($handle);
}
?>
[/code]



Edit: or maybe the file() function? Here
Copy linkTweet thisAlerts:
@ZnupiNov 09.2007 — [code=php]
$fp = fopen($filename, "r"); //Open the server log
$content = fread($fp, filesize($filename)); // Read the server log

$content = explode("n", $content); // explode into array

$content = array_reverse($content); // reverse the array

$a = 2;
$i=0;
if ($a < 3){
$i++;
// $content[$i] is now your next line in the file... so do something with it.
}
[/code]

This what you're looking for? :-
×

Success!

Help @dan_coop3r 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 4.27,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...