Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - stupid PHP questions | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 426/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-15-04 06:50 AM Link | Quote
I've been using PHP for quite a while, though there've been a few things that I haven't been able to find . I've been storing all of my data in text files.

How can I count the lines in a text file?

How do I take certain lines from a text file and put them all into one variable? (like if I wanted to take line x to y and put them in $linescontent)

How do I search through a textfile for a line (say, if I'm looking for a specific IP, for purposes of writing the IP to the file if it isn't already there)?

How do I sniff an IP? (ah, the power of Google )

This'll help a lot if I get help .


(edited by windwaker on 11-15-04 12:01 AM)
Gavin

Fuzzy
Rhinoceruses don't play games. They fucking charge your ass.
Level: 43

Posts: 306/799
EXP: 551711
For next: 13335

Since: 03-15-04
From: IL, USA

Since last post: 13 hours
Last activity: 13 hours
Posted on 11-15-04 12:12 PM Link | Quote
i apologize if it's a tad hack-ish (okay, more than a tad ;_ but I'm really not an expert PHP coder, nor am i feeling in a particularily organized mood. But nontheless, it gets done what you needed.



$filename = 'file.txt';
$contents = fread (fopen($filename, 'r'), filesize ($filename));

$file_array = split ('\n', $contents);

$line_count = count($file_array);

echo ("Lines in file: " . ($line_count + 1));
echo ("
Line 3 and 4 added: " . $file_array[3] . $file_array[4]) . "\n
";


for ($x = 0; $x < $line_count; $x++) {
$occur_count = substr_count($file_array[$x], '/');

if ($occur_count > 0) {
echo ("$occur_count matches in file $filename, on line $x
");
}
}

?>
windwaker

Ball and Chain Trooper
WHY ALL THE MAYONNAISE HATE
Level: 61

Posts: 429/1797
EXP: 1860597
For next: 15999

Since: 03-15-04

Since last post: 4 days
Last activity: 6 days
Posted on 11-15-04 08:15 PM Link | Quote


This'll help -tons- and tons and tons. Thanks Gav!
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - stupid PHP questions | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.007 seconds.