Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3963978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:16:45+00:00 2026-05-20T03:16:45+00:00

i have some php arrays saved in a .log file i want to read

  • 0

i have some php arrays saved in a .log file

i want to read them into a php array such as

array[0] = 1st array in the .log file
array1 = 2nd array in the .log file

the solution here does not work for me

it gives no such file or directory error but when i do include_once(‘file.log’) the content in the file is displayed as the output ( i dont know why ) please help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:16:45+00:00Added an answer on May 20, 2026 at 3:16 am

    You could serialize the array before writing it as text to a file. Then, you can read the data back out of the file, unserialize will turn it back into an array.

    http://php.net/manual/en/function.serialize.php

    EDIT Describing the process of using serialize/unserialize:

    So you have an array:

    $arr = array(
      'one'=>array(
          'subdata1',
          'subdata2'
      ),
      'two'='12345'
    );
    

    When I call serialize on that array, I get a string:

    $string = serialize($arr);
    echo $string;
    
    OUTPUT: a:2:{s:3:"one";a:2:{i:0;s:8:"subdata1";i:1;s:8:"subdata2";}s:3:"two";s:5:"12345";}
    

    So I want to write that data into a file:

    $fn= "serialtest.txt";
    $fh = fopen($fn, 'w');
    fwrite($fh, $string);
    fclose($fh);
    

    Later, I want to use that array. So, I’ll read the file, then unserialize:

    $str = file_get_contents('serialtest.txt');
    $arr = unserialize($str);
    print_r($arr);
    
    OUTPUT: Array ( [one] => Array ( [0] => subdata1 [1] => subdata2 ) [two] => 12345 ) 
    

    Hope that helps!

    EDIT 2 Nesting demo

    To store more arrays into this file over time, you have to create a parent array. This array is a container for all the data, so when you want to add another array, you have to unpack the parent, and add your new data to that, then repack the whole thing.

    First, get your container set up:

    // Do this the first time, just to create the parent container
    $parent = array();
    $string = serialize($arr);
    $fn= "logdata.log";
    $fh = fopen($fn, 'w');
    fwrite($fh, $string);
    fclose($fh);
    

    Now, from there forward, when you want to add a new array, first you have to get the whole package out and unserialize it:

    // get out the parent container
    $parent = unserialize(file_get_contents('logdata.log'));
    
    // now add your new data
    $parent[] = array(
      'this'=>'is',
      'a'=>'new',
      'array'=>'for',
      'the'=>'log'
    );
    
    // now pack it up again
    $fh = fopen('logdata.log', 'w');
    fwrite($fh, serialize($parent));
    fclose($fh);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some php files in a server which generate xml code in them.
I have some PHP code which allows me to sort a column into ascending
If I have some php classes inside a namespace com\test and want to import
I have an ajax request sending some data to a php file: Ext.Ajax.request({ url:
im being played by php and DomDocument.... basically i have some html saved in
I have some PHP code that generates dynamic tables of data on the fly.
I have some PHP code that is designed to make a spreadsheet with formulas
I have some PHP code that generates a calendar and then outputs html to
I have some PHP code which stores whatever is typed in a textbox in
So I have some PHP code that looks like: $message = 'Here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.