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 6674255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:43:25+00:00 2026-05-26T03:43:25+00:00

I want to create a simple logfile in PHP that later can be read

  • 0

I want to create a simple logfile in PHP that later can be read by PHP.

This logfile should look like this:

1303942306 26.4 "Lore ipsum 1" 84.169.73.55 appname1 
1303942308 28.8 "Lore ipsum 2" 84.169.73.55 appname2
1304078658 31.2 "Lore ipsum 3" 80.187.103.95 appname3

As you can see it is supposed to contain the following variables:

$timestamp
$float
$text (with spaces and other special characters)
$ip
$appname

Until now there was no need to save text (with spaces) within this logfile, so I could use a simple fscanf function.

I’ve tried to use “|” as a delimiter with fscanf – but, well, it has a few “glitches” ;-):

//write to file
$statisticsfile = fopen("user.history",'a+b');
     fputs($statisticsfile, time().' | '.$float.' | '.$text.' | '.$_SERVER['REMOTE_ADDR'].' | '.$appname."\r\n");

//read from file
    while ($userinfo = fscanf($statisticsfile, "%[0-9] | %[0-9.-] | %[a-zA-Z0-9 ,] | %[0-9.] | %[0-9]")) 
{list ($timestamp[], $float[], $text[], $ip[], $appname[]) = $userinfo;}

This code creates three problems:

  1. It skips the first line in the logfile
  2. the text can only contain letters and number (and all other special characters I have defined), but it such a better design if I could only exclude the delimiter
  3. is fscanf really the best (fastest, least memory-consuming) function for this task? Or would a simple fget function with a delimiter be better?

I would really appreciate your 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-26T03:43:26+00:00Added an answer on May 26, 2026 at 3:43 am

    From your sample data, seems to me that the best way to go is the built-in csv functions, fgetcsv and fputcsv. Simply use a space as your delimiter instead of a comma. These functions will automatically be mindful of the quoted values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI, I want to create simple floor plans like this and render it on
I want to create a simple http proxy server that does some very basic
I want to create a simple bit of JS code that creates an image
I want to create a simple batch file that would perform some Visual Studio
I want to create a simple menu function which can call it example get_menu()
I want to create simple custom control (derived from control and with look defined
I want to create simple file viewer. What control should i use to view
I want to create simple equalizer for android. How can I do it? Try
I want to create simple charts like pies and bars in python. I tried
I want to create simple application like android image gallery but I don't want

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.