Jump to content

reading and performing action


yhi
 Share

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

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • 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.