Acmlm's Board - I2 Archive - Programming - stupid PHP questions
User | Post |
windwaker
Posts: 429/1797 |
This'll help -tons- and tons and tons. Thanks Gav! |
Gavin
Posts: 306/799 |
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
Posts: 426/1797 |
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 . |
|