Jump to content

reading and performing action


yhi

Recommended Posts

i want my php script to read a local file ~56mb (1000+ lines)

and perform a operation on each of the lines separately

 

i am not sure how to do this

i have no clue how to properly read file 

can i use file_get _contents( ) ?

and after reading how to perform the operation on each lines separately

can i use

forreach ?

 

 

PS

it it makes ant difference

those 1000+ lines are base64encoded lines

and i want to decrypt them

each line seprately

Link to comment
Share on other sites

<?php

$handle = fopen("data.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
$current=base64_decode($line);
$file=rand();
file_put_contents($file, $current);
echo"done";
    }

    fclose($handle);
} else {
    echo"error opening the file.";
} 

?>

i wrote this script but in my output file i only got 2.97kb data

 

data.txt have 8kb data in each line

Link to comment
Share on other sites

file_put_contents replaces the content of a file by default. You can pass the FILE_APPEND flag in the third parameter to have it append to the file instead.

 

file_put_contents replaces the content of a file by default. You can pass the FILE_APPEND flag in the third parameter to have it append to the file instead.

ok but what about the size limit ?

each line is 8kb but i am only receiving 2.97ks in output

what could be the problem ?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.